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.2.tar.gz (22.7 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.2-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: errorsense-0.1.2.tar.gz
  • Upload date:
  • Size: 22.7 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.2.tar.gz
Algorithm Hash digest
SHA256 8b494639bb38cb7fb14711ad72a86f3244af1211d3ca76073a6843aea8634b29
MD5 dff4af2273c3f27d93df88fd65a0f63b
BLAKE2b-256 ca9e82fe993b29ff5dde54e82934ba5367d6b94875e661629eb5216be1d42786

See more details on using hashes here.

File details

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

File metadata

  • Download URL: errorsense-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 20.0 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 71abbb9a4b6bb8ed4a5cf6b1371005af4c718edd50793615ab2582a8cf340f96
MD5 3bd0ba3b99297dc94040a76e4c87bae8
BLAKE2b-256 405183ea7ef8d3256ec1d4eef79948e81025b2c4a22c35b76df48c50dc6538f2

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