Skip to content
Back to skills

561 Exceptions 3dbd3b44

ASecurity

Exception classes for pydantic-ai-skills error handling.

  • 9 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added May 31, 2026
ai-agentspythongoapi

Works with

  • api

Security analysis

A100/100

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

Scanned May 31, 2026

npx -y skills add tools-only/X-Skills --skill 561-exceptions_3dbd3b44 --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of 561 Exceptions 3dbd3b44?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for 561 Exceptions 3dbd3b44
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tools-only-561-exceptions-3dbd3b44/badge)](https://www.skillsdirectory.com/skills/tools-only-561-exceptions-3dbd3b44)

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
# Exceptions API Reference

Exception classes for pydantic-ai-skills error handling.

## Exception Hierarchy

```
Exception
└── SkillException (base)
    ├── SkillNotFoundError
    ├── SkillValidationError
    ├── SkillResourceLoadError
    └── SkillScriptExecutionError
```

## Exception Classes

::: pydantic_ai_skills.exceptions.SkillException
    options:
      show_source: true
      heading_level: 3

::: pydantic_ai_skills.exceptions.SkillNotFoundError
    options:
      show_source: true
      heading_level: 3

::: pydantic_ai_skills.exceptions.SkillValidationError
    options:
      show_source: true
      heading_level: 3

::: pydantic_ai_skills.exceptions.SkillResourceLoadError
    options:
      show_source: true
      heading_level: 3

::: pydantic_ai_skills.exceptions.SkillScriptExecutionError
    options:
      show_source: true
      heading_level: 3

## Usage Examples

### Handling SkillNotFoundError

```python
from pydantic_ai_skills import SkillsToolset, SkillNotFoundError

toolset = SkillsToolset(directories=["./skills"])

try:
    skill = toolset.get_skill("non-existent-skill")
except SkillNotFoundError as e:
    print(f"Error: {e}")
    print("Available skills:", list(toolset.skills.keys()))
```

### Handling SkillValidationError

```python
from pydantic_ai_skills import discover_skills, SkillValidationError

try:
    skills = discover_skills(
        directories=["./skills"],
        validate=True  # Strict validation
    )
except SkillValidationError as e:
    print(f"Skill validation failed: {e}")
```

### Handling SkillResourceLoadError

```python
from pydantic_ai_skills import SkillsToolset, SkillResourceLoadError

toolset = SkillsToolset(directories=["./skills"])
skill = toolset.get_skill("my-skill")

try:
    # Attempt to read a resource
    for resource in skill.resources:
        content = resource.path.read_text()
except SkillResourceLoadError as e:
    print(f"Failed to load resource: {e}")
```

### Handling SkillScriptExecutionError

```python
from pydantic_ai import Agent
from pydantic_ai_skills import SkillsToolset, SkillScriptExecutionError

toolset = SkillsToolset(
    directories=["./skills"],
    script_timeout=10  # 10 second timeout
)

agent = Agent(model='openai:gpt-5.2', toolsets=[toolset])

# The agent will receive an error if script times out or fails
result = await agent.run("Run the long-running-script")
# If script times out, agent will see:
# "Script 'script_name' timed out after 10 seconds"
```

### General Exception Handling

```python
from pydantic_ai_skills import (
    SkillsToolset,
    SkillException,
    SkillNotFoundError,
    SkillValidationError
)

try:
    toolset = SkillsToolset(directories=["./skills"])
    skill = toolset.get_skill("my-skill")
    # ... work with skill ...

except SkillNotFoundError as e:
    print(f"Skill not found: {e}")
except SkillValidationError as e:
    print(f"Validation error: {e}")
except SkillException as e:
    print(f"General skill error: {e}")
except Exception as e:
    print(f"Unexpected error: {e}")
```

## When Exceptions Are Raised

### SkillNotFoundError

Raised by:
- `SkillsToolset.get_skill(name)` - When skill doesn't exist

### SkillValidationError

Raised by:
- `discover_skills()` - When YAML frontmatter is invalid
- `parse_skill_md()` - When YAML parsing fails

### SkillResourceLoadError

Raised by:
- `read_skill_resource` tool - When resource file can't be read
- File I/O operations on skill resources

### SkillScriptExecutionError

Raised by:
- `run_skill_script` tool - When script execution fails or times out
- Subprocess operations on skill scripts

## Best Practices

### 1. Catch Specific Exceptions

```python
# ✅ Good - specific handling
try:
    skill = toolset.get_skill("my-skill")
except SkillNotFoundError:
    print("Skill not found, using default behavior")
    skill = None

# ❌ Bad - too broad
try:
    skill = toolset.get_skill("my-skill")
except Exception:
    pass
```

### 2. Provide Helpful Error Messages

```python
# ✅ Good - informative
try:
    skill = toolset.get_skill(skill_name)
except SkillNotFoundError:
    available = ", ".join(toolset.skills.keys())
    print(f"Skill '{skill_name}' not found.")
    print(f"Available skills: {available}")

# ❌ Bad - not helpful
try:
    skill = toolset.get_skill(skill_name)
except SkillNotFoundError:
    print("Error")
```

### 3. Log Exceptions in Production

```python
import logging
from pydantic_ai_skills import SkillException

logger = logging.getLogger(__name__)

try:
    toolset = SkillsToolset(directories=["./skills"])
except SkillException as e:
    logger.error(f"Failed to initialize skills: {e}", exc_info=True)
    # Handle gracefully
```

## See Also

- [SkillsToolset](toolset.md) - Main toolset API
- [Types](types.md) - Type definitions
- [Core Concepts](../concepts.md) - Understanding skills

Files in this skill

  • README.md799 B
  • skill.md4.8 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.