Integration

Pydantic logo

PydanticAI

PydanticAI type-safe agents integrated with ZenML

On this page

PydanticAI extends the Pydantic ecosystem with type-safe AI agents that validate structured outputs and integrate tools. Running them with ZenML puts these agents into production-ready pipelines, ensuring reproducibility, artifact lineage, and deployment flexibility.

Features with ZenML

  • Type-safe orchestration. Run PydanticAI agents inside ZenML pipelines with guaranteed structured outputs.
  • ‍Artifact tracking. Store queries, validated responses, and error cases as ZenML artifacts.
  • ‍Error handling. Integrate post-run checks or evaluation steps to catch invalid responses.
  • ‍Composable workflows. Combine PydanticAI with retrieval, evals, and deployment steps in a single pipeline.
  • ‍Portable execution. Move seamlessly from local runs to scalable orchestrators like Kubernetes or Airflow.

Main Features

  • Type-safe agents. Ensure AI outputs conform to strict schemas defined with Pydantic.
  • ‍Simple run_sync API. Call agents with a straightforward synchronous interface.
  • ‍Tool integration. Extend agents with callable Python functions as tools.

How to use ZenML with PydanticAI

text
from zenml import ExternalArtifact, pipeline, step
from pydanticai_agent import agent

@step
def run_pydanticai(query: str) -> str:
   result = agent.run_sync(query)
   return str(result.output)

@pipeline
def pydanticai_agent_pipeline() -> str:
   q = ExternalArtifact(value="What is the secret data?")
   return run_pydanticai(q.value)

if __name__ == "__main__":
   print(pydanticai_agent_pipeline())

Additional Resources

Connect Your AI Workflows
to a World of Tools

Expand your AI workflows with 66 ZenML integrations