PydanticAI Archives - gettectonic.com

pardot1084082=08782fe4994719f386e1d3c9bbd9a12817d57a65b36593fbba0e8645340e02b6

pydanticai

Pydantic AI

The evaluation of agentic applications is most effective when integrated into the development process, rather than being an afterthought. For this to succeed, developers must be able to mock both internal and external dependencies of the agent being built. PydanticAI introduces a groundbreaking framework that supports dependency injection from the start, enabling developers to build agentic applications with an evaluation-driven approach. An architectural parallel can be drawn to the historic Krakow Cloth Hall, a structure refined over centuries through evaluation-driven enhancements. Similarly, PydanticAI allows developers to iteratively address challenges during development, ensuring optimal outcomes. Challenges in Developing GenAI Applications Developers of LLM-based applications face recurring challenges, which become significant during production deployment: To address non-determinism, developers must adopt evaluation-driven development, a method akin to test-driven development. This approach focuses on designing software with guardrails, real-time monitoring, and human oversight, accommodating systems that are only x% correct. The Promise of PydanticAI PydanticAI stands out as an agent framework that supports dependency injection, model-agnostic workflows, and evaluation-driven development. Its design is Pythonic and simplifies testing by allowing the injection of mock dependencies. For instance, in contrast to frameworks like Langchain, where dependency injection is cumbersome, PydanticAI streamlines this process, making the workflows more readable and efficient. Building an Evaluation-Driven Application with PydanticAI Example Use Case: Evaluating Mountain Data By employing tools like Wikipedia as a data source, the agent can fetch accurate mountain heights during production. For testing, developers can inject mocked responses, ensuring predictable outputs and faster development cycles. Advancing Agentic Applications with PydanticAI PydanticAI provides the building blocks for creating scalable, evaluation-driven GenAI applications. Its support for dependency injection, structured outputs, and model-agnostic workflows addresses core challenges, empowering developers to create robust and adaptive LLM-powered systems. This paradigm shift ensures that evaluation is seamlessly embedded into the development lifecycle, paving the way for more reliable and efficient agentic applications. Like Related Posts Salesforce OEM AppExchange Expanding its reach beyond CRM, Salesforce.com has launched a new service called AppExchange OEM Edition, aimed at non-CRM service providers. Read more The Salesforce Story In Marc Benioff’s own words How did salesforce.com grow from a start up in a rented apartment into the world’s Read more Salesforce Jigsaw Salesforce.com, a prominent figure in cloud computing, has finalized a deal to acquire Jigsaw, a wiki-style business contact database, for Read more Service Cloud with AI-Driven Intelligence Salesforce Enhances Service Cloud with AI-Driven Intelligence Engine Data science and analytics are rapidly becoming standard features in enterprise applications, Read more

Read More

Empowering LLMs with a Robust Agent Framework

PydanticAI: Empowering LLMs with a Robust Agent Framework As the Generative AI landscape evolves at a historic pace, AI agents and multi-agent systems are expected to dominate 2025. Industry leaders like AWS, OpenAI, and Microsoft are racing to release frameworks, but among these, PydanticAI stands out for its unique integration of the powerful Pydantic library with large language models (LLMs). Why Pydantic Matters Pydantic, a Python library, simplifies data validation and parsing, making it indispensable for handling external inputs such as JSON, user data, or API responses. By automating data checks (e.g., type validation and format enforcement), Pydantic ensures data integrity while reducing errors and development effort. For instance, instead of manually validating fields like age or email, Pydantic allows you to define models that automatically enforce structure and constraints. Consider the following example: pythonCopy codefrom pydantic import BaseModel, EmailStr class User(BaseModel): name: str age: int email: EmailStr user_data = {“name”: “Alice”, “age”: 25, “email”: “[email protected]”} user = User(**user_data) print(user.name) # Alice print(user.age) # 25 print(user.email) # [email protected] If invalid data is provided (e.g., age as a string), Pydantic throws a detailed error, making debugging straightforward. What Makes PydanticAI Special Building on Pydantic’s strengths, PydanticAI brings structured, type-safe responses to LLM-based AI agents. Here are its standout features: Building an AI Agent with PydanticAI Below is an example of creating a PydanticAI-powered bank support agent. The agent interacts with customer data, evaluates risks, and provides structured advice. Installation bashCopy codepip install ‘pydantic-ai-slim[openai,vertexai,logfire]’ Example: Bank Support Agent pythonCopy codefrom dataclasses import dataclass from pydantic import BaseModel, Field from pydantic_ai import Agent, RunContext from bank_database import DatabaseConn @dataclass class SupportDependencies: customer_id: int db: DatabaseConn class SupportResult(BaseModel): support_advice: str = Field(description=”Advice for the customer”) block_card: bool = Field(description=”Whether to block the customer’s card”) risk: int = Field(description=”Risk level of the query”, ge=0, le=10) support_agent = Agent( ‘openai:gpt-4o’, deps_type=SupportDependencies, result_type=SupportResult, system_prompt=( “You are a support agent in our bank. Provide support to customers and assess risk levels.” ), ) @support_agent.system_prompt async def add_customer_name(ctx: RunContext[SupportDependencies]) -> str: customer_name = await ctx.deps.db.customer_name(id=ctx.deps.customer_id) return f”The customer’s name is {customer_name!r}” @support_agent.tool async def customer_balance(ctx: RunContext[SupportDependencies], include_pending: bool) -> float: return await ctx.deps.db.customer_balance( id=ctx.deps.customer_id, include_pending=include_pending ) async def main(): deps = SupportDependencies(customer_id=123, db=DatabaseConn()) result = await support_agent.run(‘What is my balance?’, deps=deps) print(result.data) result = await support_agent.run(‘I just lost my card!’, deps=deps) print(result.data) Key Concepts Why PydanticAI Matters PydanticAI simplifies the development of production-ready AI agents by bridging the gap between unstructured LLM outputs and structured, validated data. Its ability to handle complex workflows with type safety and its seamless integration with modern AI tools make it an essential framework for developers. As we move toward a future dominated by multi-agent AI systems, PydanticAI is poised to be a cornerstone in building reliable, scalable, and secure AI-driven applications. Like1 Related Posts Salesforce OEM AppExchange Expanding its reach beyond CRM, Salesforce.com has launched a new service called AppExchange OEM Edition, aimed at non-CRM service providers. Read more Salesforce Jigsaw Salesforce.com, a prominent figure in cloud computing, has finalized a deal to acquire Jigsaw, a wiki-style business contact database, for Read more Service Cloud with AI-Driven Intelligence Salesforce Enhances Service Cloud with AI-Driven Intelligence Engine Data science and analytics are rapidly becoming standard features in enterprise applications, Read more Health Cloud Brings Healthcare Transformation Following swiftly after last week’s successful launch of Financial Services Cloud, Salesforce has announced the second installment in its series Read more

Read More
gettectonic.com