9201ef759e
Harness Compat / harness compat (push) Failing after 0s
CI / test on 3.12 (standard) (push) Has been cancelled
CI / test on 3.13 (standard) (push) Has been cancelled
CI / test on 3.14 (standard) (push) Has been cancelled
CI / test on 3.10 (all-extras) (push) Has been cancelled
CI / test on 3.11 (all-extras) (push) Has been cancelled
CI / test on 3.12 (all-extras) (push) Has been cancelled
CI / test on 3.14 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.10 (pydantic-evals) (push) Has been cancelled
CI / test on 3.11 (pydantic-evals) (push) Has been cancelled
CI / test on 3.12 (pydantic-evals) (push) Has been cancelled
CI / deploy-docs-preview (push) Has been cancelled
CI / build release artifacts (push) Has been cancelled
CI / publish to PyPI (push) Has been cancelled
CI / Send tweet (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / mypy (push) Has been cancelled
CI / docs (push) Has been cancelled
CI / test on 3.10 (standard) (push) Has been cancelled
CI / test on 3.11 (standard) (push) Has been cancelled
CI / test on 3.13 (all-extras) (push) Has been cancelled
CI / test on 3.14 (all-extras) (push) Has been cancelled
CI / test on 3.10 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.11 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.12 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.13 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.13 (pydantic-evals) (push) Has been cancelled
CI / test on 3.14 (pydantic-evals) (push) Has been cancelled
CI / test on 3.10 (lowest-versions) (push) Has been cancelled
CI / test on 3.11 (lowest-versions) (push) Has been cancelled
CI / test on 3.12 (lowest-versions) (push) Has been cancelled
CI / test on 3.13 (lowest-versions) (push) Has been cancelled
CI / test on 3.14 (lowest-versions) (push) Has been cancelled
CI / test examples on 3.11 (push) Has been cancelled
CI / test examples on 3.12 (push) Has been cancelled
CI / test examples on 3.13 (push) Has been cancelled
CI / test examples on 3.14 (push) Has been cancelled
CI / coverage (push) Has been cancelled
CI / check (push) Has been cancelled
CI / deploy-docs (push) Has been cancelled
33 lines
774 B
Python
33 lines
774 B
Python
"""Simple example of using Pydantic AI to construct a Pydantic model from a text input.
|
|
|
|
Run with:
|
|
|
|
uv run -m pydantic_ai_examples.pydantic_model
|
|
"""
|
|
|
|
import os
|
|
|
|
import logfire
|
|
from pydantic import BaseModel
|
|
|
|
from pydantic_ai import Agent
|
|
|
|
# 'if-token-present' means nothing will be sent (and the example will work) if you don't have logfire configured
|
|
logfire.configure(send_to_logfire='if-token-present')
|
|
logfire.instrument_pydantic_ai()
|
|
|
|
|
|
class MyModel(BaseModel):
|
|
city: str
|
|
country: str
|
|
|
|
|
|
model = os.getenv('PYDANTIC_AI_MODEL', 'openai:gpt-5.2')
|
|
print(f'Using model: {model}')
|
|
agent = Agent(model, output_type=MyModel)
|
|
|
|
if __name__ == '__main__':
|
|
result = agent.run_sync('The windy city in the US of A.')
|
|
print(result.output)
|
|
print(result.usage)
|