A model returns valid JSON. The application parses it and invokes a tool. That sequence establishes only that the text could be parsed, not that the action is meaningful, bounded, or authorized.
Treat tool arguments as untrusted input even when the model provider supports structured outputs. Model-side constraints can improve consistency, but the application remains responsible for deciding what may execute.
Validate three different properties
First, validate structure: required fields, types, and unexpected properties. Next, validate meaning: supported operations, numeric ranges, and combinations the tool can actually perform. Finally, authorize the action against current application state.
| Layer | Example rejection | What it does not prove |
|---|---|---|
| Structure | A string where an integer is required | The integer is in a safe range |
| Meaning | A negative export limit or unsupported operation | The caller owns the requested records |
| Authorization | Another tenant’s document ID | The result is appropriate to send elsewhere |
Keep failures at the earliest applicable layer. A malformed proposal should not reach a network request just to discover that the receiving service also rejects it.
Bound work before parsing and execution
Limit the input size before parsing large text. Then bound collections, string lengths, numeric values, and the amount of work an accepted argument can request. A small JSON object can still ask for millions of records.
Use explicit types. Coercing "100", true, and 100 into the same value can conceal a contract mismatch. Reject non-finite values and unsafe integers where exact counts matter.
Decide how duplicate fields are handled by the parser and every intermediary. If one layer validates a first value while another executes a last value, the system may disagree about what was approved. Do not assume every JSON implementation shares your interpretation.
Expose narrow operations
Prefer a small named operation with defined arguments to a general command string. Keep shell commands, SQL fragments, and executable expressions out of model-controlled parameters when a structured operation covers the task.
An allowed operation still needs a safe implementation. Use parameterized database queries, platform file APIs, and destination controls appropriate to the operation. Validating the string “read_document” does not make an unsafe path lookup secure.
Reject extra properties when they could alter execution. A model-provided admin, tenantId, or skipApproval field must not become authority because an object was forwarded wholesale to a downstream function.
Preserve the boundary through transformations
Validate the same normalized representation that will execute. If later code expands a URL, resolves a path, adds defaults, or selects a different account, those changes can affect the decision and need their own checks.
For irreversible actions, bind approval to the final representation. If the recipient or content changes after approval, require a new decision. The approval tutorial demonstrates that property in a local program.
Return a bounded result to the agent. A safe input path can still leak data through an overly broad tool response or a raw exception. Keep internal errors and credentials out of model-visible messages.
Test malformed and plausible-but-wrong requests
Use a permitted request as the control. Then test missing and additional fields, nulls, arrays in place of objects, oversized strings, duplicate identifiers, boundary integers, and a well-formed request for an unauthorized resource.
Check that rejected input produces no protected effect. A validation error after a tool has already sent a message is not a successful rejection. Use synthetic fixtures and a delivery or write counter in an authorized environment.
Also check that the validator detects a deliberate regression, such as removing the operation allowlist. A test suite that only checks successful parsing cannot protect the execution contract.
Keep these checks beside the tool implementation and rerun them when its arguments change. Limited tool permissions and validation solve different parts of the same problem: what the agent can reach, and which proposed actions that access is allowed to perform.
