{
 "schema_version": 1,
 "generated": "2026-10-31",
 "id": "pydantic-pydantic-ai--extract-typed-data-with-an-llm",
 "repo": "pydantic/pydantic-ai",
 "repo_url": "https://github.com/pydantic/pydantic-ai",
 "repo_slug": "pydantic-pydantic-ai",
 "title": "Get validated, typed data out of an LLM",
 "page_title": "How to get validated, typed data out of an LLM with Pydantic AI",
 "summary": "Give a Pydantic AI agent an output type and tools so every run returns a checked Pydantic model.",
 "who": "A developer parsing reviews, tickets or emails who is tired of fixing malformed JSON from a model.",
 "problem": "Free-text model output breaks downstream code when fields are missing or out of range.",
 "outcome": "An agent whose result.output is a validated Pydantic model, with tools whose arguments are validated too.",
 "steps": [
  "Install with `uv add pydantic-ai`",
  "Define a Pydantic BaseModel for the output, for example a Sentiment with a label and a score between -1 and 1",
  "Create an Agent with your model string and output_type set to that model",
  "Add data sources with the @agent.tool decorator; the signature and docstring become the tool schema",
  "Call run_sync and use result.output as typed data"
 ],
 "agent_prompt": "Using pydantic/pydantic-ai, build an agent with output_type=<Pydantic model> that extracts <fields> from <input type>. Add a tool that fetches <data>, run it on three examples and show the validated outputs.",
 "agents": [
  "claude-code",
  "codex",
  "cursor"
 ],
 "difficulty": "Beginner",
 "time": "20 minutes",
 "basis": "readme",
 "caveat": "Validation guarantees the shape of the answer, not that the model judged it correctly, so spot check results.",
 "category": "Software and DevOps",
 "tags": [
  "Software and DevOps"
 ],
 "lang": "python",
 "requirements": [
  "Python and uv",
  "An API key for the model provider you choose",
  "Optional extras: pydantic-ai-harness[coder], pydantic-ai[temporal] and a Temporal setup, pydantic-ai[openai-realtime]",
  "Optional: a Logfire account for tracing"
 ],
 "risk": "none",
 "seen_in_the_wild": false,
 "mentioned_publicly": false,
 "risks": [],
 "best": true,
 "score": 1.0,
 "evidence": [],
 "url": "https://dedupedai.com/use-cases/pydantic-pydantic-ai/extract-typed-data-with-an-llm/",
 "md": "https://dedupedai.com/use-cases/pydantic-pydantic-ai/extract-typed-data-with-an-llm/index.md",
 "disclaimer": "Deduped lists open-source repositories that belong to other people. We do not own, maintain, audit, or vouch for any of them, and a repo appearing here is not an endorsement or a safety check. The use cases, steps, and prompts are written by AI and may be incomplete, outdated, or just wrong. Where a use case is marked \"Seen in the wild\", we link to public posts where someone described something similar, but we have not verified those posts and the use case itself is still our AI's own write-up. Use all of this at your own risk. Only run code, commands, or agents on systems and accounts you are authorized to use, and read the code and every command before you run it, especially anything that touches credentials, files, or the network. Nothing here is professional, security, legal, or financial advice. All trademarks and project names belong to their respective owners, and their use here does not imply affiliation. Content is provided as is, without warranties of any kind. Found a mistake, a safety problem, or something you want removed? Email hello@dedupedai.com and we will look at it promptly.",
 "api": "https://dedupedai.com/api/v1/usecases/pydantic-pydantic-ai--extract-typed-data-with-an-llm.json",
 "api_version": "v1"
}
