Skip to content
Back to full roadmap
topiccore

Structured Output for Tool Args

Tool arguments must be 100% valid JSON — schema enforcement + retry.

2 hours2 resources1 prereqs

Agent tool calls = JSON. Broken JSON or schema mismatch → agent crashes. Solutions:

  1. Native function calling: OpenAI/Anthropic/Gemini built-in. Validates schema, retries.
  2. Constraint decoding (open-source): Outlines, guidance — token-level enforcement.
  3. Pydantic + retry: on parse fail, re-prompt with the error. PydanticAI does this built-in.
  4. Few-shot examples: for complex schemas, add 1-2 input/output samples.

Best practice: in tool descriptions, explicitly mark required fields and state defaults for optional ones.

Prerequisites

Resources(2)

Structured Output for Tool Args · AI Agent Engineer Roadmap | SYK