Lesson 28 of 38 · Written learning
Structured outputs and tool calls
Use schemas and validation to turn free-form model output into safer application data.
Natural-language text is flexible but can be ambiguous. A schema defines required fields, types, and allowed values. Structured-output features can help a model produce JSON that matches a format, but parsing is not the same as validating meaning. Check ranges, permissions, and business rules in ordinary code.
Keep the model separate from the action
A tool call is a request from the model to use a capability. The application decides whether the tool exists, validates its arguments, executes it, and returns a result. Start with read-only tools. A valid JSON object can still request the wrong record or an unsafe action, so authorization must be enforced outside the model.
if request.tool == "lookup_public_record":
args = validate_schema(request.arguments)
result = lookup_public_record(args)
else:
reject_unknown_tool()- Use narrow tool names and typed arguments.
- Reject unexpected fields and out-of-range values.
- Do not put API secrets in user-visible prompts.
- Log tool decisions carefully while avoiding unnecessary sensitive data.
Return to the LLM application engineering and agents stage · Suggested timing is flexible; move at your own pace.