Prompt Chain

Evaluate Pydantic AI Agents with Promptfoo

Promptfoo example evaluating PydanticAI agents with structured-output validation and multiple assertion types.

Works with pydantic

82
Spark score
out of 100
Updated 25 days ago
Version code-scan-action-0.1

Add to Favorites

Why it matters

Streamline AI agent development by evaluating PydanticAI agents using promptfoo. Ensure structured outputs and type safety for robust AI applications.

Outcomes

What it gets done

01

Evaluate PydanticAI agent performance

02

Test structured output generation

03

Debug AI agent behavior

04

Ensure type safety in AI applications

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/pfoo-integration-pydantic-ai | bash

Steps

Steps in the chain

01
Initialize example project
02
Navigate to project directory
03
Install Python dependencies
04
Set OpenAI API key
05
Run evaluation
06
View results

Overview

Integration Pydantic Ai

A promptfoo example running a PydanticAI weather agent through promptfoo's Python provider, evaluated with JSON schema, JavaScript, Python, and LLM-rubric assertions. Use when your agent is built with PydanticAI and you need to validate its structured outputs and tool usage through promptfoo.

What it does

This example demonstrates how to evaluate PydanticAI agents using promptfoo. PydanticAI is a Python agent framework that provides structured outputs and type safety for AI applications. The example builds a simple PydanticAI weather agent with structured output and runs it through promptfoo's Python provider so its behavior can be evaluated like any other promptfoo target.

When to use - and when NOT to

Use this example when your agent is built with PydanticAI and you want to validate its structured outputs and tool usage through promptfoo's assertion system - JSON schema validation, JavaScript checks, Python checks, and LLM-rubric evaluations. It is not a general PydanticAI tutorial; it only shows the minimal wiring needed to run a PydanticAI agent through promptfoo's Python provider.

Inputs and outputs

npx promptfoo@latest init --example integration-pydantic-ai
cd integration-pydantic-ai
pip install -r requirements.txt
export OPENAI_API_KEY=your_openai_api_key_here
npx promptfoo@latest eval
npx promptfoo@latest view

The example is structured around four files: agent.py (the PydanticAI weather agent with structured output), provider.py (the promptfoo Python provider that runs the agent), promptfooconfig.yaml (the evaluation configuration with diverse assertion types), and requirements.txt (the Python dependencies). It demonstrates JSON schema validation via is-json assertions alongside JavaScript, Python, and LLM-rubric assertion types, and shows how to evaluate the agent's tool usage as part of the eval.

Integrations

Integrates PydanticAI (a Python agent framework for structured, type-safe AI outputs) with promptfoo's Python provider interface, requiring an OPENAI_API_KEY since the agent calls OpenAI.

Who it's for

Teams building agents with PydanticAI who want to evaluate structured output correctness, JSON schema compliance, and tool usage using promptfoo's assertion system instead of writing bespoke test harnesses.

Source README

integration-pydantic-ai (Pydantic AI Integration)

This example demonstrates how to evaluate PydanticAI agents using promptfoo. PydanticAI is a Python agent framework that provides structured outputs and type safety for AI applications.

You can run this example with:

npx promptfoo@latest init --example integration-pydantic-ai
cd integration-pydantic-ai

Quick Start

cd integration-pydantic-ai
pip install -r requirements.txt
export OPENAI_API_KEY=your_openai_api_key_here
npx promptfoo@latest eval
npx promptfoo@latest view

What This Shows

  • Creating a PydanticAI agent with structured outputs
  • Using promptfoo's Python provider to evaluate agents
  • JSON schema validation with is-json assertions
  • Multiple assertion types: JavaScript, Python, and LLM-rubric evaluations
  • Evaluating agent tool usage

Example Structure

  • agent.py - Simple PydanticAI weather agent with structured output
  • provider.py - Promptfoo Python provider that runs the agent
  • promptfooconfig.yaml - Evaluation configuration with diverse assertion types
  • requirements.txt - Python dependencies

FAQ

Common questions

Discussion

Questions & comments ยท 0

Sign In Sign in to leave a comment.