Skip to content
Back to skills

502 2026 01 28 Pydantic Ai Adapter Layer 39a80dd5

ASecurity

Remove 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
code-qualitygobash

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned June 1, 2026

npx -y skills add tools-only/X-Skills --skill 502-2026-01-28_pydantic-ai-adapter-layer_39a80dd5 --agent claude-code

Installs into .claude/skills of the current project.

Are 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.

Security grade badge for 502 2026 01 28 Pydantic Ai Adapter Layer 39a80dd5
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tools-only-502-2026-01-28-pydantic-ai-adapter-layer-39a80dd5/badge)](https://www.skillsdirectory.com/skills/tools-only-502-2026-01-28-pydantic-ai-adapter-layer-39a80dd5)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
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.md1016 B
  • skill.md1.4 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.