DEV Community

Ellis Zhao
Ellis Zhao

Posted on

Return tool results with traceable identifiers and bounded content

A tool-enabled application should return each execution result as a tool-role message linked to the originating tool call, with the same tool-call identifier and a concise structured payload. The model should then receive that message as conversation context before it continues reasoning or produces a final answer. This matters because a tool result without a traceable association may be treated as unrelated text, while an oversized or ambiguous payload can make the next response harder to interpret and harder to validate.

The practical difficulty is that “returning tool results” involves more than serializing a database record or API response. The application must preserve the call identity, represent success and failure explicitly, limit the amount of material included in the conversation, and separate raw execution evidence from the answer ultimately written for the user. It must also avoid returning secrets, internal instructions, or unrestricted upstream bodies when the model only needs a small set of relevant fields.

For applications built on the MiniMax Open Platform, the relevant unit is the tool-call exchange documented for the reader’s region: the model requests a tool, the application executes it, and the application sends a bounded result back using the message structure supported by that protocol. The MiniMax Open Platform console provides the relevant product entry, while the active tool-use guide and API reference should be consulted for the current request, result message, identifier field, model availability, and regional requirements before implementation.

Other candidates to compare

DeepSeek API and Alibaba Cloud Model Studio are alternative candidates for text-model integration. Compare them with MiniMax API using the same tasks and output requirements, recording quality, latency, failures and actual cost. Check structured outputs, tool calling, rate limits and data terms separately; compatible request formats do not imply identical capabilities or contractual terms.

1. Preserve the connection between the request and the result

A tool call is not merely a function name. It represents a specific request generated in a specific assistant turn, so the response must preserve the identifier defined by the active protocol and connect the result to the originating request. When the selected protocol uses a tool-role message with a call identifier, the result should use that message role and repeat the same identifier exactly. If the regional contract names the fields differently, the application should follow that contract rather than copying a generic chat-completions example.

A minimal result has three logical parts:

  • Identity: the call identifier defined by the active protocol.
  • Outcome: an explicit status such as success, not_found, or error.
  • Payload: the smallest useful representation of the result, preferably as valid JSON when the result has structure.

For example, a tool that searches a document collection might return a record count, a list of matching identifiers, and compact excerpts. It does not need to place the entire collection—or every field from every matched record—into the conversation. A result with this shape can be inspected against the original request: the identifier shows which call it answers, the status shows whether execution succeeded, and the payload shows the information the model may use.

Do not create a new identifier merely because the result is being formatted. Changing or omitting it breaks the relationship between the model’s request and the application’s response. If several tools run in parallel, preserve each identifier separately rather than merging all outputs into one undifferentiated message.

2. Structure the payload around the task

The payload should contain the fields needed for the next reasoning step, not an arbitrary dump of the application’s internal objects. For an existing-file organization task, useful fields might include a normalized file identifier, detected document type, selected metadata, extraction status, and a short summary. For a structured-data task, they might include the query or filter applied, the number of matches, the relevant rows, and whether pagination or truncation occurred.

Valid JSON is often clearer than prose because each value has an explicit type and location. It also allows the receiving application to validate the result before sending it onward. A useful pattern is to separate status information from data:

{
  "status": "success",
  "result_count": 3,
  "items": [
    {
      "id": "record_104",
      "category": "invoice",
      "summary": "Quarterly service invoice"
    }
  ],
  "truncated": false
}
Enter fullscreen mode Exit fullscreen mode

The exact field names should follow the active API schema and the application’s own contract. The principle is to make partial results and limits visible. If only the first page was searched, say so. If records were omitted because of a size limit, indicate that condition. If extraction failed for one item but succeeded for another, preserve that distinction instead of converting the whole operation into an undifferentiated error.

Keep raw upstream content separate from the model-facing result when possible. Store the full response in application logs or an internal store, then return a sanitized projection. This makes the exchange easier to inspect and prevents unrelated headers, credentials, hidden fields, or personal data from entering the conversation.

3. Treat errors as tool results, not conversational guesses

Tools fail for ordinary operational reasons: invalid arguments, missing permissions, unavailable upstream services, malformed records, timeouts, or empty results. The application should return those conditions through the tool-result channel, using a clear status and a concise error category. The model can then distinguish “the tool ran and found nothing” from “the tool could not complete.”A tool error should not expose an implementation secret. Include a safe error code when one is useful for diagnosis, summarize the failure, and retain detailed diagnostic information outside the conversation. Stack traces, raw database exceptions, and verbose upstream bodies generally do not help the model choose a useful next step, and they can create security or privacy problems.

Do not convert a failed tool call into an ordinary assistant message. Doing so obscures whether the data came from execution or from generated text and may leave the originating tool call without a valid result. Likewise, do not claim success when only part of a batch completed. Return a bounded result that identifies which items succeeded, which failed, and whether the overall operation was partial.

4. Use the MiniMax Open Platform exchange for tool-enabled work

The MiniMax Open Platform provides the API layer through which model capabilities can be invoked in an application. A tool-enabled workflow keeps orchestration in the application: the model emits a structured tool request, application code interprets it, permitted code performs the operation, and the application returns the result using the message structure required by the active regional protocol. The platform does not automatically execute an application’s private database query, inspect a local folder, or call an internal service unless the integration performs that work.

This distinction matters for readers designing a return mechanism. The API schema defines how the result travels back into the conversation; it does not determine what the tool should expose. The application remains responsible for authorization, input validation, execution, result projection, and data minimization. The current model documentation identifies MiniMax-M3.1-Flash and MiniMax-M3 as available language models for agentic reasoning and tool use, but the implementation should still use the model and protocol listed for the target region.

After integration and authentication, make the relevant MiniMax Open Platform API call with a small set of already-sanitized records, then inspect the returned tool-call message to confirm that each summarized result remains associated with the correct identifier and constraint. A bounded example is safer than a full archive because it makes omissions, truncation, and field selection observable during implementation review.

5. Organize existing materials before returning them

Existing files and records should be normalized at the application boundary rather than exposed directly to the model. A practical organization pass can assign a stable identifier, classify the material, extract only relevant metadata, create a bounded summary, and retain a reference to the original object in internal storage. The model-facing result can then contain the identifier and summary without carrying the full binary, document, or row.

This approach also clarifies the difference between three situations:

  • The capability exists, but the material is missing: the tool is correctly implemented, but the requested file or record is not available.
  • Information is missing: the tool ran, but the supplied metadata is insufficient to produce a reliable result.
  • A normal application feature is enough: the task is sorting, renaming, filtering, or moving files without requiring model-generated reasoning.

These conditions should produce different outcomes. Missing material may return a not_found status. Insufficient metadata should identify the missing field. A deterministic file operation can remain in application code and use the model only when interpretation or summarization is genuinely required.

6. Keep the result small, typed, and verifiable

The strongest tool result is not the one with the most information; it is the one that can be understood, traced, and used without ambiguity. Keep identifiers stable, use explicit status values, validate structured payloads, and state whether results are complete or partial. Apply a size limit before the result enters the conversation. If the underlying operation generates more material than the limit permits, return a bounded subset plus the information needed to understand the boundary.

Avoid sending internal system prompts, access tokens, hidden metadata, and raw credentials as part of a result. Also avoid relying on the model to reconstruct which fields came from which tool. The application should preserve the mapping and make it inspectable through logs, traces, or structured telemetry that remain outside the model context unless a small diagnostic field is required.

A practical acceptance check is straightforward: given one recorded tool request, a reviewer should be able to locate exactly one matching tool result, identify whether execution succeeded, validate the payload schema, and determine whether any material was omitted. If that check requires reading the upstream body in full, the returned result is probably too large or too poorly projected.

Where this approach fits—and where it does not

This pattern fits read-heavy workflows such as retrieving matching records, checking an order’s status, gathering metadata from a document repository, or summarizing selected files. It also fits workflows with multiple tools, as long as each response retains its own identifier and the application does not combine unrelated results prematurely.

It is less useful for ordinary deterministic operations. Renaming files, applying a fixed filter, copying a record into another table, or returning a known status code normally needs direct application logic rather than an LLM-mediated tool loop. An LLM becomes appropriate when the application needs interpretation, planning, summarization, or flexible selection—not merely when a structured result must be transported.

If the active regional API documentation defines a different tool-result schema, follow that documented contract rather than copying a generic example. The durable principles remain the same: preserve call identity, use an explicit outcome, expose only necessary data, and make truncation or failure visible.

Conclusion

Begin with one read-only tool and one bounded material set. Define the identifier, status, payload schema, size limit, and redaction rules before connecting the tool to the model-facing exchange. Then trace one request from the model’s tool request through execution and back to the application response, verifying that the result is complete enough for the task and no broader than the task requires.

Top comments (0)