pydanticai-docs
Use this skill for requests related to Pydantic AI framework - building agents, tools, dependencies, structured outputs, and model integrations.
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o pydanticai-docs.zip https://jpskill.com/download/18846.zip && unzip -o pydanticai-docs.zip && rm pydanticai-docs.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/18846.zip -OutFile "$d\pydanticai-docs.zip"; Expand-Archive "$d\pydanticai-docs.zip" -DestinationPath $d -Force; ri "$d\pydanticai-docs.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
pydanticai-docs.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
pydanticai-docsフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
Pydantic AI ドキュメンテーションスキル
概要
このスキルは、本番環境レベルの生成AIアプリケーションを構築するためのPythonエージェントフレームワークである Pydantic AI の使用に関するガイダンスを提供します。Pydantic AI は、型安全性、依存性注入、および構造化された出力を重視しています。
主要な概念
エージェント
エージェントは、LLMと対話するための主要なインターフェースです。これには以下が含まれます。
- 指示 (Instructions): LLMへのシステムプロンプト
- ツール (Tools): LLMが呼び出すことができる関数
- 出力タイプ (Output Type): LLMが返さなければならない構造化されたデータ型
- 依存関係 (Dependencies): ツールとプロンプトに注入されるデータ/サービス
モデル
Pydantic AI は、モデル識別子を介して複数のLLMプロバイダーをサポートしています。
ツール呼び出しをサポートするすべてのモデルは、pydantic-ai-skills で使用できます。
ツール
ツールの種類は2つあります。
@agent.tool: 依存関係を持つRunContextを受け取ります@agent.tool_plain: コンテキストを持たないプレーンな関数
ツールセット
エージェントに登録できるツールのコレクションです。
FunctionToolset: 複数のツールをグループ化しますMCPServerTool: モデルコンテキストプロトコルサーバー- サードパーティ製ツールセット (ACI.dev など)
手順
1. 完全なドキュメントの取得
包括的な情報については、Pydantic AI の完全なドキュメントを取得してください: https://ai.pydantic.dev/llms.txt
これには、エージェント、ツール、依存関係、モデル、およびAPIリファレンスを含む完全なドキュメントが含まれています。
2. クイックリファレンス
基本的なエージェントの作成
from pydantic_ai import Agent
agent = Agent('openai:gpt-5.2')
result = agent.run_sync('What is the capital of France?')
print(result.output)
ツールを持つエージェント
from pydantic_ai import Agent, RunContext
agent = Agent('openai:gpt-5.2', deps_type=str)
@agent.tool
def get_user_name(ctx: RunContext[str]) -> str:
"""Get the current user's name."""
return ctx.deps
result = agent.run_sync('What is my name?', deps='Alice')
構造化された出力
from pydantic import BaseModel
from pydantic_ai import Agent
class CityInfo(BaseModel):
name: str
country: str
population: int
agent = Agent('openai:gpt-5.2', output_type=CityInfo)
result = agent.run_sync('Tell me about Paris')
print(result.output) # CityInfo(name='Paris', country='France', population=...)
依存関係
from dataclasses import dataclass
from pydantic_ai import Agent, RunContext
@dataclass
class MyDeps:
api_key: str
user_id: int
agent = Agent('openai:gpt-5.2', deps_type=MyDeps)
@agent.tool
async def fetch_data(ctx: RunContext[MyDeps]) -> str:
# Access dependencies via ctx.deps
return f"User {ctx.deps.user_id}"
ツールセットの使用
from pydantic_ai import Agent
from pydantic_ai.toolsets import FunctionToolset
toolset = FunctionToolset()
@toolset.tool
def search(query: str) -> str:
"""Search for information."""
return f"Results for: {query}"
agent = Agent('openai:gpt-5.2', toolsets=[toolset])
非同期実行
import asyncio
from pydantic_ai import Agent
agent = Agent('openai:gpt-5.2')
async def main():
result = await agent.run('Hello!')
print(result.output)
asyncio.run(main())
ストリーミング
from pydantic_ai import Agent
agent = Agent('openai:gpt-5.2')
async with agent.run_stream('Tell me a story') as response:
async for text in response.stream():
print(text, end='', flush=True)
3. 一般的なパターン
動的な指示
@agent.instructions
async def add_context(ctx: RunContext[MyDeps]) -> str:
return f"Current user ID: {ctx.deps.user_id}"
システムプロンプト
@agent.system_prompt
def add_system_info() -> str:
return "You are a helpful assistant."
リトライ付きツール
@agent.tool(retries=3)
def unreliable_api(query: str) -> str:
"""Call an unreliable API."""
...
Override を使用したテスト
from pydantic_ai.models.test import TestModel
with agent.override(model=TestModel()):
result = agent.run_sync('Test prompt')
4. インストール
# フルインストール
pip install pydantic-ai
# スリムインストール (特定のモデル)
pip install "pydantic-ai-slim[openai]"
5. ベストプラクティス
- 型安全性: より良いIDEサポートのために、常に
deps_typeとoutput_typeを定義してください。 - 依存性注入: データベース接続、APIクライアントなどに deps を使用してください。
- 構造化された出力: 検証済みで型付けされた応答には Pydantic モデルを使用してください。
- エラー処理: 信頼性の低いツールには
retriesパラメータを使用してください。 - テスト: 単体テストには
TestModelまたはoverride()を使用してください。
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Pydantic AI Documentation Skill
Overview
This skill provides guidance for using Pydantic AI - a Python agent framework for building production-grade Generative AI applications. Pydantic AI emphasizes type safety, dependency injection, and structured outputs.
Key Concepts
Agents
Agents are the primary interface for interacting with LLMs. They contain:
- Instructions: System prompts for the LLM
- Tools: Functions the LLM can call
- Output Type: Structured datatype the LLM must return
- Dependencies: Data/services injected into tools and prompts
Models
Pydantic AI supports multiple LLM providers via model identifiers.
All models that supports tool-calling can be used with pydantic-ai-skills.
Tools
Two types of tools:
@agent.tool: ReceivesRunContextwith dependencies@agent.tool_plain: Plain function without context
Toolsets
Collections of tools that can be registered with agents:
FunctionToolset: Group multiple toolsMCPServerTool: Model Context Protocol servers- Third-party toolsets (ACI.dev, etc.)
Instructions
1. Fetch Full Documentation
For comprehensive information, fetch the complete Pydantic AI documentation: https://ai.pydantic.dev/llms.txt
This contains complete documentation including agents, tools, dependencies, models, and API reference.
2. Quick Reference
Basic Agent Creation
from pydantic_ai import Agent
agent = Agent('openai:gpt-5.2')
result = agent.run_sync('What is the capital of France?')
print(result.output)
Agent with Tools
from pydantic_ai import Agent, RunContext
agent = Agent('openai:gpt-5.2', deps_type=str)
@agent.tool
def get_user_name(ctx: RunContext[str]) -> str:
"""Get the current user's name."""
return ctx.deps
result = agent.run_sync('What is my name?', deps='Alice')
Structured Output
from pydantic import BaseModel
from pydantic_ai import Agent
class CityInfo(BaseModel):
name: str
country: str
population: int
agent = Agent('openai:gpt-5.2', output_type=CityInfo)
result = agent.run_sync('Tell me about Paris')
print(result.output) # CityInfo(name='Paris', country='France', population=...)
Dependencies
from dataclasses import dataclass
from pydantic_ai import Agent, RunContext
@dataclass
class MyDeps:
api_key: str
user_id: int
agent = Agent('openai:gpt-5.2', deps_type=MyDeps)
@agent.tool
async def fetch_data(ctx: RunContext[MyDeps]) -> str:
# Access dependencies via ctx.deps
return f"User {ctx.deps.user_id}"
Using Toolsets
from pydantic_ai import Agent
from pydantic_ai.toolsets import FunctionToolset
toolset = FunctionToolset()
@toolset.tool
def search(query: str) -> str:
"""Search for information."""
return f"Results for: {query}"
agent = Agent('openai:gpt-5.2', toolsets=[toolset])
Async Execution
import asyncio
from pydantic_ai import Agent
agent = Agent('openai:gpt-5.2')
async def main():
result = await agent.run('Hello!')
print(result.output)
asyncio.run(main())
Streaming
from pydantic_ai import Agent
agent = Agent('openai:gpt-5.2')
async with agent.run_stream('Tell me a story') as response:
async for text in response.stream():
print(text, end='', flush=True)
3. Common Patterns
Dynamic Instructions
@agent.instructions
async def add_context(ctx: RunContext[MyDeps]) -> str:
return f"Current user ID: {ctx.deps.user_id}"
System Prompts
@agent.system_prompt
def add_system_info() -> str:
return "You are a helpful assistant."
Tool with Retries
@agent.tool(retries=3)
def unreliable_api(query: str) -> str:
"""Call an unreliable API."""
...
Testing with Override
from pydantic_ai.models.test import TestModel
with agent.override(model=TestModel()):
result = agent.run_sync('Test prompt')
4. Installation
# Full installation
pip install pydantic-ai
# Slim installation (specific model)
pip install "pydantic-ai-slim[openai]"
5. Best Practices
- Type Safety: Always define
deps_typeandoutput_typefor better IDE support - Dependency Injection: Use deps for database connections, API clients, etc.
- Structured Outputs: Use Pydantic models for validated, typed responses
- Error Handling: Use
retriesparameter for unreliable tools - Testing: Use
TestModeloroverride()for unit tests