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.1.1.tar.gz (68.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.1.1-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: actionable_errors-0.1.1.tar.gz
  • Upload date:
  • Size: 68.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.1.1.tar.gz
Algorithm Hash digest
SHA256 bd102184f10658e5041e92046e6f544782342cce48ba7a0db8195ef6303e4318
MD5 1e0b3270f052b853eb1373ae81fd77dd
BLAKE2b-256 4551a370e9437ebfa79cb9f521614ed2bf3debd97a0c3d1c34879cb9a1b0afcb

See more details on using hashes here.

Provenance

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

Publisher: publish.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.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for actionable_errors-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 185e1e5c24c0264f4f02ccf855a8d55ea999882b9884f06f34c8c1cc34202774
MD5 a77f468d4d748408d846373536019611
BLAKE2b-256 7b31c56059b7c9327e16731756d113ce7346ad8e617e115f555cec5c2213a884

See more details on using hashes here.

Provenance

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

Publisher: publish.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