Skip to main content

Three-audience error framework: typed errors for code, actionable suggestions for humans, tool guidance for AI agents

Project description

actionable-errors

CI Coverage PyPI

Three-audience error framework for Python.

Every ActionableError speaks to three audiences simultaneously:

Audience Uses Provided by
Calling code Typed ErrorType for routing (retry? escalate? ignore?) ErrorType(StrEnum) — 8 base categories
Human operator suggestion + Troubleshooting steps Frozen dataclasses with actionable text
AI agent AIGuidance with concrete next tool calls Frozen dataclass with tool suggestions

Install

pip install actionable-errors

Zero runtime dependencies — stdlib only. Sits at the bottom of every dependency tree.

Quick Start

from actionable_errors import (
    ActionableError,
    AIGuidance,
    ToolResult,
    from_exception,
    sanitize,
)

# Domain-specific factory with built-in defaults
error = ActionableError.authentication(
    service="Azure DevOps",
    raw_error="401 Unauthorized",
)
print(error.suggestion)    # "Check your credentials and try again."
print(error.ai_guidance)   # AIGuidance(action_required="Re-authenticate", command="az login")

# Auto-classify any exception
try:
    raise ConnectionError("Connection refused")
except Exception as exc:
    ae = from_exception(exc, service="Kusto", operation="query")
    print(ae.error_type)   # "connection"

# Typed result envelope for MCP tool responses
result = ToolResult.ok(data={"items": 42})
result = ToolResult.fail(error=error)     # extracts error_type + suggestion

# Credential sanitization
clean = sanitize('password="hunter2" token=abc123')
# → 'password="***" token=***'

Extending ErrorType

Python StrEnum can't be subclassed once it has members, so extend via composition:

from enum import StrEnum
from actionable_errors import ActionableError

class RAGErrorType(StrEnum):
    EMBEDDING = "embedding"
    INDEX = "index"

error = ActionableError(
    error="Vector store unavailable",
    error_type=RAGErrorType.INDEX,
    service="pinecone",
    suggestion="Check Pinecone cluster status.",
)

Factories

Eight domain-specific factories with sensible defaults:

Factory Key Parameters
.authentication(service, raw_error) Default suggestion + AI guidance
.configuration(field_name, reason)
.connection(service, url, raw_error)
.timeout(service, operation, timeout_seconds)
.permission(service, resource, raw_error)
.validation(service, field_name, reason)
.not_found(service, resource_type, resource_id, raw_error)
.internal(service, operation, raw_error)

All factories accept optional suggestion, ai_guidance, and troubleshooting kwargs.

Development

# Install dev dependencies
uv sync --extra dev

# Run all checks
task check  # lint → type → test (90 tests, 100% coverage)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

actionable_errors-0.2.0.tar.gz (84.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

actionable_errors-0.2.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file actionable_errors-0.2.0.tar.gz.

File metadata

  • Download URL: actionable_errors-0.2.0.tar.gz
  • Upload date:
  • Size: 84.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for actionable_errors-0.2.0.tar.gz
Algorithm Hash digest
SHA256 715170439e1075ae4b4110a490c651fd061cd353f9d838a8d0bbce5e45adb439
MD5 9a59eab7f00af6a2406f34b46fad50f7
BLAKE2b-256 6e0e0627633686a0d802b00bd50c55a4318e319fa2722718e31dc0d73dda01d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for actionable_errors-0.2.0.tar.gz:

Publisher: release.yml on grimlor/actionable-errors

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file actionable_errors-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for actionable_errors-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fb2cb16b499b86c87ce0c2c5f598c1cf8101551683b2d73eb6af8db98571ed7f
MD5 ab4c5b1d5e2c4350ec813be29d5da793
BLAKE2b-256 aa1b93cf054ce58cd8b010cf85dd3acb77f72dbc9be12427a4d84e8e736a0125

See more details on using hashes here.

Provenance

The following attestation bundles were made for actionable_errors-0.2.0-py3-none-any.whl:

Publisher: release.yml on grimlor/actionable-errors

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page