Designing Multimodal Model Applications: Integration, Evaluation, and Risk Control
This article explains how to design a general multimodal model application before choosing a specific model. It covers capability checks, image and text input rules, task design for agents, code changes, and multi-step knowledge work, plus API service design, data classification, and evaluation metrics.
1. Confirm the model’s capability boundaries first
This article does not discuss parameters for any specific model. Vendors differ widely in model versions, context length, pricing, and API fields. Before going live, use the official documentation for the model you select.
During project planning, confirm each of the following:
- Whether the model accepts text and image input, and which image formats and size limits it supports
- The maximum context length, and whether content beyond that limit is truncated or rejected with an error
- Whether tool calling is supported, and what the parameter and response formats are
- Whether structured output is supported, meaning the model can return results in a specified JSON structure
- Whether data may be used for model training, how long it is retained, and whether private or regional deployment is available
The answers shape the rest of the design. For example, if structured output is not supported, the server must parse free-form text itself, and the failure rate will rise noticeably.
2. Input and output patterns, and rules for using images
The model’s primary output is text. Text input is appropriate for requirements, code snippets, configuration, logs, and structured task descriptions. Image input is appropriate for UI screenshots, flowcharts, tables, architecture diagrams, and error pages.
Images reduce the cost of transcribing information. Developers can send a UI screenshot and ask the model to point out layout issues. Operations staff can submit a monitoring screenshot and ask the model to identify unusual time ranges and related metrics. Business users can upload a table and ask the model to extract fields and describe how they relate.
When using images, follow these rules:
- Keep screenshots clear. Key text should not be so small that it is hard to read.
- If part of the image is obscured or cropped, say so in the prompt.
- When analyzing a chart, require the model to separate “facts visible in the image” from “conclusions drawn from those facts,” and attach the corresponding location in the image to each conclusion.
- Visual interpretation must be reviewed by a person. Do not treat it directly as the basis for a production decision.
Desensitize images before sending them. The table below lists common content and how to handle it.
| Content type | Handling requirement |
|---|---|
| Faces and ID photos | Mask before sending, or do not send |
| Keys, tokens, and passwords | Do not send; rotate immediately if found |
| Internal addresses and hostnames | Replace with placeholders, such as HOST_A |
| Phone numbers, email addresses, and national ID numbers | Replace with masks while keeping the format |
| Customer lists and contract amounts | Desensitize before sending, and keep the field structure |
3. Task design for typical scenarios
3.1 Agent workflows
The core of an agent is to let the model plan steps and call tools within an authorized scope. The example below is “summarize last week’s tickets and draft a weekly report.”
- Goal parsing. Require the model to return JSON with three fields:
task_type,inputs, andconstraints. Validation succeeds when the JSON parses and all three fields are present. On failure, retry once; if it still fails, hand the task to a person. - Tool calls. Expose only a tool that reads ticket export files, and restrict it to a read-only directory. Cap tool calls at five per task.
- Result checks. The number of summarized records must match the number of valid rows in the source file. The priority field may only be P0, P1, P2, or P3. Mark any other value as an exception.
- Draft generation. Save the weekly-report draft in a review directory. Do not send it to anyone automatically.
Stop the workflow immediately and report to the user if any of the following occurs: the tool returns an error twice in a row; tool calls exceed five; or the model asks to write, delete, or send. On stop, keep intermediate results from completed steps so a person can take over.
3.2 Writing and refactoring code
Code refactoring works better in small steps. The example is refactoring an order-parsing function, parse_order().
The input includes the full source of the old function, the runtime (Python 3.11), the return-value structure that must stay unchanged, and the current unit-test results.
The output includes the revised function, the corresponding diff, and a list of callers that may be affected. The model should state which callers depend on which fields in the return value.
Acceptance criteria:
- All existing unit tests pass.
- At least five new boundary tests are added, covering empty input, invalid amounts, time-zone boundaries, duplicate order IDs, and overly long strings.
- The new code passes static checks with no new warnings.
Failure handling works as follows. When a test fails, send the failing case and the original error to the model, and ask it to fix only the failing part. Each round of changes should touch only one function. If the tests still fail after three consecutive rounds, stop automatic edits and hand the work to a developer.
Do not ask the model to rewrite an entire system in one pass. When the scope is too large, the model is likely to miss implicit dependencies and change interface behavior or compatibility.
3.3 Multi-step knowledge work
For tasks such as meeting notes, report writing, and document classification, the key is a verifiable processing chain, not a request for the final answer alone.
For a batch of meeting notes, the chain can be:
- Extract source facts, and attach the source file name and paragraph number to each fact.
- Mark the time of each fact.
- Merge entries that use different wording but say the same thing.
- Find contradictory entries and list both sides of each conflict.
- Classify by topic and generate an outline.
- Write a summary in which every sentence can be traced back to a fact from the previous step.
- Output a list of questions that still need human confirmation.
For acceptance, randomly sample 30 facts from the output and compare each one with the source. A factual agreement rate of at least 95% can be treated as passing a pilot. For contracts or financial information, raise the threshold to 99%.
4. Engineering design for API integration
Wrap model calls in a separate service layer. Business modules should reach the model only through that layer. The service layer handles authentication, timeouts, retries, logging, content filtering, cost tracking, and version switching in one place. Changing the model version or the retry policy then requires a change in only one location.
4.1 Example request structure
{"request_id": "req_20261125_000123","idempotency_key": "ticket-88213-summary-v1","model": "injected from configuration; not hardcoded in business code","prompt_template": "ticket_summary","template_version": "2.3.0","input": {"ticket_text": "desensitized ticket body"},"output_schema": {"issue_type": "string","impact_scope": "string","priority": "P0|P1|P2|P3","recommended_action": "string","items_to_confirm": "array"},"timeout_ms": 30000,"max_retries": 2}
Field notes: request_id is used for tracing. idempotency_key prevents duplicate execution; the same business action runs only once within the server-side deduplication window, which should be 24 hours. template_version records the prompt-template version so results can be traced. output_schema is used by the server to validate the response structure.
4.2 Retry rules
Timeouts, rate limiting (HTTP 429), and server errors (HTTP 5xx) may be retried. Use exponential backoff: wait about 1 second before the first retry and about 2 seconds before the second, and add random jitter so many requests do not resend at the same time.
Parameter errors (HTTP 400) and schema-validation failures should not be retried, because the same input will produce the same error.
The key to avoiding duplicate execution is to check, before a retry, whether the idempotency_key already has a result. If it does, return that result and do not call the model or run the business action again.
4.3 Error codes and handling
| Error code | Meaning | Handling |
|---|---|---|
| E_TIMEOUT | Exceeded timeout_ms |
Follow the retry rules |
| E_RATE_LIMIT | Request rate exceeded the limit | Back off and retry |
| E_SCHEMA_INVALID | Response does not match output_schema |
Retry once; if it still fails, hand off to a person |
| E_SENSITIVE_BLOCKED | Desensitization check failed | Do not call the model; log and alert |
| E_POLICY_REJECT | The model refused to answer, or the content was filtered | Hand off to a person; do not retry automatically |
4.4 Log fields
Each call should record: request_id, idempotency_key, template_version, model_version, latency_ms, status, retry_count, input and output token counts, and the reviewer ID.
Do not log raw sensitive content. When debugging is required, log a hash of the desensitized content and use that hash to relate the log to the original text in controlled storage.
4.5 Version switching
When a new model version goes live, start with 5% of traffic for 3 days. During that period, compare the old and new versions on task completion rate, format compliance rate, and average response time. After the metrics meet the target, increase traffic by 20% per day until the cutover is complete.
Keep a rollback switch that can return traffic to the previous version within 5 minutes.
5. Data classification and the permission matrix
When a model application uses enterprise data, security design must come before feature design. First classify the data. Then define how each class is handled.
| Data class | Examples | May it be sent to an external model? | Handling requirement | Audit fields |
|---|---|---|---|---|
| Public | Published product documentation | Yes | No extra handling | Call time, template version |
| Internal | Internal process descriptions | Yes, with approval from the owner | Restrict access roles | Caller, call time, data source |
| Sensitive | Customer phone numbers, contract amounts | Only after desensitization | Field replacement, hashing, or deletion | Desensitization-rule version, validation record of the desensitized result |
| Highly sensitive | Private keys, plaintext production databases, personal ID documents | Do not send | Process only locally or in a controlled environment | Rejection records, alert records |
By default, the model service account is read-only. Tool calls that write data may run only after approval. Store secrets in a secrets manager or in environment variables. Do not put them in frontend code, public repositories, or ordinary logs.
6. Evaluation metrics and thresholds
Judging model quality from a few demos is unreliable. Build a fixed evaluation set that covers common inputs, boundary inputs, abnormal inputs, and high-risk inputs, with the three sample groups each making up about one third.
The metrics below are recommended starting points. Adjust the thresholds for business risk and historical data.
- Task completion rate: the number of tasks that pass rule checks divided by the total number of tasks. Use a sample of at least 200 tasks. A suggested threshold is 85% or higher.
- Output format compliance rate: the number of responses that pass
output_schemavalidation divided by the total number of responses. A suggested threshold is 98% or higher. - Factual accuracy: among extracted factual statements, the number that match the source divided by the total number of extracted statements. Use a sample of at least 400 statements. A suggested threshold is 95% or higher in general cases, and 99% or higher for high-risk cases such as contracts and finance.
- Code first-pass rate: after the code is generated, the first run…
