Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:PrefectHQ Prefect DataAnalysis Output Model

From Leeroopedia


Metadata
Source Repo: Prefect
Domains AI_Agents, Data_Validation
Last Updated 2026-02-09 00:00 GMT

Overview

Concrete Pydantic model defining the structured output schema for the AI data analyst agent in Prefect workflows.

Description

The DataAnalysis BaseModel defines the schema for AI agent output with four fields: summary (str), key_findings (list[str] with min/max length), recommendations (list[str] with min/max length), and columns_analyzed (list[str]). It includes a custom __str__ method for formatted display. This is a Pattern Doc since it defines a user-created schema rather than a library API.

Code Reference

class DataAnalysis(BaseModel):
    """Structured analysis results from the AI agent."""
    summary: str = Field(description="High-level summary of the dataset")
    key_findings: list[str] = Field(
        description="Key findings discovered from the data",
        min_length=3, max_length=5
    )
    recommendations: list[str] = Field(
        description="Actionable recommendations based on the findings",
        min_length=3, max_length=5,
    )
    columns_analyzed: list[str] = Field(
        description="List of columns that were analyzed"
    )
  • Import: from pydantic import BaseModel, Field

I/O Contract

Direction Name Type Description
Input (LLM output) JSON LLM generates JSON matching this schema
Output summary str High-level summary of the dataset
Output key_findings list[str] (3-5 items) Key findings discovered from the data
Output recommendations list[str] (3-5 items) Actionable recommendations based on findings
Output columns_analyzed list[str] List of columns that were analyzed

Usage Example

from pydantic import BaseModel, Field
from pydantic_ai import Agent

class DataAnalysis(BaseModel):
    summary: str = Field(description="High-level summary")
    key_findings: list[str] = Field(min_length=3, max_length=5)
    recommendations: list[str] = Field(min_length=3, max_length=5)
    columns_analyzed: list[str]

agent = Agent("openai:gpt-4o", output_type=DataAnalysis)
result = await agent.run("Analyze the dataset", deps=df)

# result.output is a validated DataAnalysis instance
print(result.output.summary)
print(result.output.key_findings)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment