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.0All lessons in this course
- Idempotent Tools and Side Effects
- Retries with Exponential Backoff
- Timeouts and Circuit Breakers
- Validating Tool Outputs (Pydantic)