Back to skills
SKILL.md
502 2026 01 28 Pydantic Ai Adapter Layer 39a80dd5
ASecurityRemove the direct dependency on `pydantic-ai` from `src/tunacode/tools/`. Tools should raise domain-specific exceptions, not framework-specific exceptions.
- 9 stars
- 0 votes
- 0 copies
- 2 views
- Added June 1, 2026
Security analysis
100/100Pro scans all 2 files and shows the line behind each finding
npx -y skills add tools-only/X-Skills --skill 502-2026-01-28_pydantic-ai-adapter-layer_39a80dd5 --agent claude-codeAre you the author of 502 2026 01 28 Pydantic Ai Adapter Layer 39a80dd5?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/tools-only-502-2026-01-28-pydantic-ai-adapter-layer-39a80dd5)---
title: "Decouple Tools from Pydantic-AI"
phase: Completed
date: "2026-01-28"
owner: "architecture"
tags: [architecture, decoupling, pydantic-ai, refactor]
---
## Goal
Remove the direct dependency on `pydantic-ai` from `src/tunacode/tools/`.
Tools should raise domain-specific exceptions, not framework-specific exceptions.
## Strategy
1. **Define Protocol:** Create `ToolRetryError` in `src/tunacode/exceptions.py`.
2. **Adapter Layer:** Update `src/tunacode/tools/decorators.py` to catch `ToolRetryError` and re-raise `pydantic_ai.ModelRetry`.
3. **Refactor Tools:** Update all tools to raise `ToolRetryError` instead of `ModelRetry`.
## Steps (Executed 2026-01-28)
### Step 1: Define Exception
- Added `ToolRetryError` to `src/tunacode/exceptions.py`.
### Step 2: Update Decorator
- Modified `src/tunacode/tools/decorators.py` to catch `ToolRetryError` and re-raise `ModelRetry`.
- This acts as the translation layer between our internal tool protocol and the Pydantic-AI framework.
### Step 3: Migrate Tools
- Replaced `ModelRetry` with `ToolRetryError` in:
- `tools/bash.py`
- `tools/glob.py`
- `tools/grep.py`
- `tools/list_dir.py`
- `tools/update_file.py`
- `tools/web_fetch.py`
- `tools/write_file.py`
## Verification
`grep -r "pydantic_ai" src/tunacode/tools/` returns only `decorators.py`.
Dependencies are now correctly directed: `tools` -> `exceptions` <- `decorator` -> `pydantic-ai`.
Files in this skill
- README.md
- skill.md
Attribution
Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.