BaseModel is pydantic’s foundation for declaring typed, validated, schema-driven data models. Subclass it to describe the structured data your application expects, then reuse built-in validation, type checking, and serialization. section 9.3.1
Model an answer evaluation
A quiz application can define two required fields: `is_correct: bool` and `correct_answer: str`. An `AnswerEvaluation` subclass of BaseModel gives the LLM a precise response schema and lets the application read `evaluation.is_correct` and `evaluation.correct_answer` directly. section 9.3.1
Listing 9.5 The AnswerEvaluation class in answer_evaluation.py
from pydantic import BaseModel
class AnswerEvaluation(BaseModel):
is_correct: bool
correct_answer: str
Inspect the minimal AnswerEvaluation model, including its BaseModel inheritance and typed fields. section 9.3.1
BaseModel resembles a dataclass but provides more extensive validation and related functionality. Its internal implementation can remain out of sight while the model serves as a contract between generated data and application code. section 9.3.1
