Learn Structured Outputs & Function Calling on AI4AI — short, hands-on lessons with live AI runs, at three reading levels (beginner to expert). Free to start.
When an AI responds in plain prose, extracting specific values requires fragile string parsing or regex — both break whenever phrasing varies. Structured output solves this by constraining the model to return data in a defined schema (usually JSON), so downstream code can access…
JSON mode and schema-constrained generation solve the same problem from two different angles: making model output reliably parseable by your code. **JSON mode** (e.g., `response_format: {type: "json_object"}` in OpenAI) guarantees the response is syntactically valid JSON — no pr…
⚡ Tool calling (also called function calling) lets a language model request external actions by outputting structured JSON instead of prose. The model does not execute anything itself — it produces a tool call object that names a function and its arguments, then pauses. Your app…
A tool schema is the contract the model reads to decide whether to call a tool and how to fill its inputs. The model does not execute logic — it reads your schema like documentation and reasons about intent. Three parts matter most. First, the name: use a verb-noun pattern in sn…
LLMs occasionally return output that fails schema validation — wrong data types, missing required fields, truncated JSON from hitting the token limit, or prose mixed in before the opening brace. A production app must never trust raw model output blindly. The standard defense is …
An agent is a model that decides which tools to call, executes them in sequence, and uses each result to inform its next decision. Structured outputs — enforced via JSON Schema on tool definitions — make this reliable: the model can only emit arguments that conform to the declar…