0Pricing
AI Agents · Lesson

Validating Tool Outputs (Pydantic)

Parse every tool output through a Pydantic model — fail loud on a malformed response.

Trust But Verify

Tool outputs come from the outside world — APIs, web pages, models. A malformed or unexpected response can crash your agent or, worse, silently feed bad data into the LLM.

Validate every tool output against a schema.

Pydantic Models

Define expected shapes:

from pydantic import BaseModel, HttpUrl

class SearchResult(BaseModel):
    title: str
    url: HttpUrl
    snippet: str
    score: float = 0.0

All lessons in this course

  1. Idempotent Tools and Side Effects
  2. Retries with Exponential Backoff
  3. Timeouts and Circuit Breakers
  4. Validating Tool Outputs (Pydantic)
← Back to AI Agents