A library that validates and parses data against a typed schema, raising clear errors when it does not match. It is the standard way to enforce structured LLM output and API request bodies.
from pydantic import BaseModel, Field
class Answer(BaseModel):
answer: str
confidence: float = Field(ge=0, le=1)
sources: list[str] = []
a = Answer(answer="Paris", confidence="0.9") # "0.9" coerced to 0.9