Skip to content
Tools and function calling

02.03 · Concept

Validating what comes back

Treat model-supplied arguments as untrusted input and validate before executing.

Model-generated tool arguments are untrusted input and must be validated before any side effect runs. A schema helps with shape, but application code still needs to check types, required fields, ranges, permissions, allowed resources, and business rules before executing the requested function.

What this lesson answers

  • how to validate model tool arguments
  • are structured outputs safe to execute
  • where should function call validation happen

Notes

When an AI model returns tool or function arguments, treat them like a request from the public internet, not like data produced by your own code. The model may misunderstand the user, omit required fields, invent values, choose the wrong type, or produce something that is syntactically valid but unsafe for your business rules. Validation is the boundary between language generation and real side effects.

A useful mental model is an HTTP API endpoint. The model is the client, the tool is your backend, and the function schema is only the first contract.

Common questions

Why is a function schema not enough validation?
A schema can make the model return data in the expected format, but it cannot prove the request is allowed or safe. The model may still provide an unauthorised identifier, an excessive date range, a forbidden file path, or a value that violates business rules.
What should be checked before running a tool call?
Parse the arguments and validate required fields, types, ranges, enum values, permissions, allowed resources, and domain constraints. Treat the call like an external API request. If any check fails, do not execute the tool; return a clear error or ask for corrected input.
How should invalid model-supplied arguments be handled?
Reject them before they reach code with side effects. Return a specific validation error, ask the model or user to correct the input, or choose a safe fallback. The model proposes an action, but trusted application code decides whether that action may run.