By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
The model's output is untrusted input. It can be wrong, malformed, or steered by text in a retrieved document. Validation is not defensive programming; it is the architecture.
def validate(name, args, registry, allowed_for_task):
if name not in registry:
return "UNKNOWN_TOOL"
if name not in allowed_for_task:
return "NOT_PERMITTED_FOR_TASK"
schema = registry[name]
for arg in schema["required"]:
if arg not in args:
return f"MISSING_ARG:{arg}"
for arg, value in args.items():
if arg not in schema["properties"]:
return f"UNEXPECTED_ARG:{arg}"
expected = schema["properties"][arg]["type"]
if not type_matches(value, expected):
return f"BAD_TYPE:{arg}"
return "OK"| Principle | In practice | Why |
|---|---|---|
| Scope to the task | The research agent gets search/read, not refund/delete | An injection cannot reach what is not there |
| Scope to the user | Every data tool filters by the authenticated customer | Stops cross-tenant leakage |
| Scope to the entity | create_return(order_id) verifies ownership before acting | Stops acting on the wrong record |
| Require approval for irreversible actions | Refunds, deploys, emails: a human clicks | Policy outside the model |
A rejection should tell the model what to do next: MISSING_ARG:query is actionable. Error: invalid request is not, and the model will usually retry the same call.
Key takeaways
Model output is untrusted input; validate name, shape, types and policy.
Scope tools to task, user and entity; require approval for irreversible actions.
Prompt-level rules cannot enforce permissions — code must.
Return structured, actionable errors so the agent can correct itself.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.