Skip to content
47% off: the complete course for $79 (reg. $149)Order now →
AI Builder
Module 4Intermediate

Structured Outputs & Tool Use

Getting typed data out and letting models call your code

Make model output reliable enough to drive software: schema-constrained outputs with Zod and Pydantic, validation and repair, tool use for in-app features, generative UI, and where MCP fits into a product.

Lessons
8
Reading time
83 min
Level
Intermediate
Access
Full course

Lessons in this module

  1. 4.1

    Structured Outputs in Practice

    Get guaranteed-valid JSON from a model with schema-constrained decoding, parse it into typed objects, and know the limits of what the guarantee covers.

    11 min
  2. 4.2

    Designing Output Schemas with Zod and Pydantic

    Schema design choices that change answer quality: field order, enums, descriptions, optional vs. nullable, and reasoning fields that come before the answer.

    10 min
  3. 4.3

    Validation, Retries, and Repair

    Schema-valid isn't the same as correct. Add business-rule validation, targeted retries with feedback, and graceful fallbacks when output still fails.

    10 min
  4. 4.4

    Tool Use for App Features

    Let a model look things up and take actions inside your product — defining tools, running the call-and-return cycle, and keeping it bounded.

    10 min
  5. 4.5

    Tools That Read and Write Your App's Data

    Expose your app's existing API as model tools with the user's own permissions, confirmation steps for writes, and audit logs for everything.

    10 min
  6. 4.6

    Generative UI: Rendering Components from Model Output

    Go beyond text: have the model choose and fill real UI components — cards, forms, charts — while your code stays in charge of what renders.

    10 min
  7. 4.7

    Multi-Step Tool Flows (and When You Need an Agent)

    Chain a few tool calls into a reliable feature, cap the steps, and recognize the point where you've crossed into agent territory.

    11 min
  8. 4.8

    MCP for App Builders

    What the Model Context Protocol means for a product team: connecting MCP servers to your features, exposing your product to AI clients, and the security trade-offs.

    11 min

About this module

Most AI features don't end with text on a screen. They end with code doing something: setting a field, saving a record, rendering a component, or calling an API. Structured outputs and tool use are the two techniques that make that possible. Structured outputs constrain a language model to produce JSON that matches a schema you define, so your code can parse it into typed objects. Tool use, also called function calling, lets a model ask your application to run a function, such as looking up an order or searching help articles, and then use the result in its answer.

Both techniques are easy to demo and surprisingly easy to get wrong in production. Schema-valid output can still be factually wrong. Tool-using features can loop, run up costs, leak data across accounts, or take actions a user never approved. The difference between a feature that works and one that causes incidents is in the details: how you design the schema, what you validate after the response arrives, whose permissions a tool runs with, and where a human confirms before anything changes.

This module covers those details with working TypeScript and Python code. You'll start with schema-constrained decoding and exactly what it guarantees, then learn schema design choices that improve answer quality, and add business-rule validation with targeted retries and fallbacks. From there you'll build tool-using features: read-only lookups with hard limits, tools over your own API that respect user permissions and require confirmation for writes, generative UI that renders real components from model output, and multi-step flows with budgets.

The module ends with the Model Context Protocol (MCP), the open standard for connecting AI applications to external tools, and what it means for product teams on both sides: connecting third-party MCP servers to your features, and exposing your own product to AI assistants, along with the security trade-offs each brings.

Questions about Structured Outputs & Tool Use

What are structured outputs in LLMs?

Structured outputs are a provider feature that constrains a model's response to match a JSON Schema you supply. The schema is compiled into rules that block invalid tokens during generation, so completed responses always parse and have the required fields. They don't guarantee the values are correct, so you still need validation.

What is the difference between structured outputs and function calling?

Structured outputs shape the model's final answer into JSON your code consumes. Function calling (tool use) lets the model request that your application run a function, then continue with the result. Use structured outputs when you want data back, and tools when the model needs to look something up or take an action.

How do I make LLM JSON output reliable?

Use schema-constrained decoding rather than asking for JSON in the prompt, handle refusals and truncation as separate outcomes, and validate business rules in code after parsing. When validation fails, retry once with specific feedback about what was wrong, then fall back to a safe default or human review.

Is it safe to let an AI model call my app's API?

It can be, if tools run with the signed-in user's own permissions, scope comes from the session rather than model input, and write actions become proposals the user confirms. Log every tool call in an audit trail and treat tool results as untrusted input, since they can contain injected instructions.

What is MCP and do I need it for my app?

The Model Context Protocol is an open standard for connecting AI applications to external tools and data. You need it when your product should work with many third-party services that offer MCP servers, or when you want customers to use your product from AI assistants. For tools over your own data, plain tool definitions are simpler.