Skip to main content

Error classification engine. Rules for the obvious, AI for the ambiguous.

Project description

ErrorSense

Error classification engine. Rules for the obvious, LLM for the ambiguous.

Most errors are easy to classify — a 400 is a client error, a 502 is a server error. But some aren't — a 500 with "model not found" in the body is actually a client error, not a server failure. Your rules can't catch every edge case. An LLM can.

ErrorSense runs errors through a phase pipeline: fast deterministic rulesets first, LLM only when rulesets can't decide. Most errors never hit the LLM. The ones that do get classified correctly instead of falling through as "unknown."

Use it for: circuit breakers, alert routing, retry logic, error dashboards; anywhere you need to know what kind of error happened, not just that it happened.

Install

pip install errorsense              # core only (zero dependencies)
pip install errorsense[llm]         # + LLM classification

Quick Start — Use a Preset

from errorsense.presets import http
from errorsense import LLMConfig, Signal

sense = http(llm=LLMConfig(api_key="your_api_key"))

results = sense.classify(Signal.from_http(status_code=400, body="bad request"))
results[0].label  # "client"

results = sense.classify(Signal.from_http(status_code=502))
results[0].label  # "server"

results = sense.classify(Signal.from_http(status_code=500, body="model not found"))
results[0].label  # "client" (LLM figured it out)

The http preset gives you a 3-phase pipeline (rules → patterns → LLM) with 3 categories: "client", "server", "undecided". Rulesets handle obvious cases instantly. LLM handles the ambiguous ones.

Don't want LLM? Use http_no_llm() — rulesets only, ambiguous errors come back as "undecided".

Build Your Own Pipeline

A pipeline is a list of phases. Each phase has rulesets (deterministic) or skills (LLM). You can mix both, use only rulesets, or use only skills.

from errorsense import ErrorSense, Phase, Ruleset, Skill, LLMConfig, Signal

# Rulesets + LLM
sense = ErrorSense(
    categories=["transient", "permanent", "user"],
    pipeline=[
        Phase("codes", rulesets=[
            Ruleset(field="error_code", match={
                "ECONNRESET": "transient", "ETIMEOUT": "transient", "EPERM": "permanent",
            }),
        ]),
        Phase("patterns", rulesets=[
            Ruleset(field="message", patterns=[
                ("transient", [r"timeout", r"connection reset", r"retry"]),
                ("permanent", [r"corruption", r"fatal"]),
            ]),
        ]),
        Phase("llm", skills=[
            Skill("my_classifier", path="./skills/my_classifier.md"),
        ], llm=LLMConfig(api_key="your_key")),
    ],
    default="transient",
)

# Rulesets only — no LLM needed
sense = ErrorSense(
    categories=["client", "server"],
    pipeline=[
        Phase("rules", rulesets=[
            Ruleset(field="status_code", match={"4xx": "client", 502: "server"}),
        ]),
    ],
    default="server",
)

# LLM only — skip rulesets entirely
sense = ErrorSense(
    categories=["client", "server"],
    pipeline=[
        Phase("llm", skills=[
            Skill("my_classifier", path="./skills/my_classifier.md"),
        ], llm=LLMConfig(api_key="your_key")),
    ],
    default="unknown",
)

Phases run in order. First match wins. Rulesets are instant and free. LLM is the fallback.

Rulesets

Each ruleset does one thing — match= for field matching or patterns= for regex:

Ruleset(field="status_code", match={400: "client", 502: "server"})         # exact match
Ruleset(field="status_code", match={"4xx": "client", 503: "server"})       # range match
Ruleset(field="headers.content-type", match={"text/html": "server"})       # header match
Ruleset(field="body.error.type", match={"validation_error": "client"})     # JSON dot-path
Ruleset(field="body", patterns=[("server", [r"OOM"]), ("client", [r"invalid"])])  # regex

Custom logic? Subclass:

class VendorBugRuleset(Ruleset):
    def classify(self, signal: Signal) -> SenseResult | None:
        if signal.get("vendor") == "acme" and signal.get("code") == "X99":
            return SenseResult(label="known_bug", confidence=1.0)
        return None

Skills

Skills are LLM instructions stored as .md files. Each skill teaches the LLM how to classify errors in a specific domain.

# Loads from errorsense/skills/http_classifier.md (built-in)
Skill("http_classifier")

# Loads from your own file
Skill("my_classifier", path="./skills/my_classifier.md")

All Phases Mode

# Default — stops at first match
results = sense.classify(signal)

# All phases run
results = sense.classify(signal, short_circuit=False)

# With LLM reasoning
results = sense.classify(signal, explain=True)
results[0].reason  # "ECONNRESET indicates transient network failure"

Trailing (Stateful Error Tracking)

Track errors per key. When a threshold is hit, the LLM reviews the full error history.

from errorsense import TrailingConfig

sense = ErrorSense(
    categories=["transient", "permanent", "user"],
    pipeline=[...],
    trailing=TrailingConfig(
        threshold=3,
        count_labels=["transient", "permanent"],  # user errors don't count
    ),
)

# In your error handler:
result = sense.trail("service-a", signal)
result.label         # "transient"
result.at_threshold  # True (3rd counted error)
result.reason        # LLM review: "3 transient errors — all connection resets..."

# On success:
sense.reset("service-a")

How it works:

  • Each trail() call classifies the signal normally through the pipeline
  • Counted labels accumulate per key toward the threshold
  • At threshold, the LLM reviews all recorded errors and gives its verdict
  • If the review changes the label, the history entry is corrected and the count adjusts
  • review=False in TrailingConfig disables LLM review (just counting)

Manual review anytime:

verdict = sense.review("service-a")
verdict.label   # LLM's verdict on the full history
verdict.reason  # explanation

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

errorsense-0.1.1.tar.gz (22.1 kB view details)

Uploaded Source

Built Distribution

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

errorsense-0.1.1-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: errorsense-0.1.1.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for errorsense-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2796cbd36c4ec0ae55db75a7c8ab374bf61b132a567c3da3a197de26013bf895
MD5 81735b4de93115fea8de6a00ccbdacab
BLAKE2b-256 eb570e30051a75eaa10932653b66f883e596f932411c64e82cc154fe046356c0

See more details on using hashes here.

File details

Details for the file errorsense-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: errorsense-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 19.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for errorsense-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f505229c13dce57d21d683789b732e59d1af8945eaa13c04a233b4afd9b93651
MD5 028b88d1151786fa4b9e365f4add0a7a
BLAKE2b-256 acbda7c31daede1d0a4890684d69f1165e7754b2f211f3a1b4d23a144827bc64

See more details on using hashes here.

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