A previous release had provenance metadata, but this release does not. View details.
shadow-debugger
Background error diagnosis for Python apps and web APIs.
When an exception or HTTP 500 happens, shadow-debugger captures the stack frame from your code, strips secrets from local variables and request data, and sends the context to an LLM in a background worker thread. Your app returns its normal response right away; a few seconds later you get a Markdown postmortem in ./shadow_reports/.
It works offline with Ollama (zero external dependencies) or with Gemini, OpenAI (including OpenAI-compatible endpoints like Groq, vLLM, LM Studio), and Anthropic.
What a report looks like
Given a crashing endpoint:
@app.get("/checkout/{order_id}")
async def checkout(order_id: int, discount_items: int = 0):
unit_discount = 50 / discount_items
return {"order_id": order_id, "discount": unit_discount}
shadow-debugger writes shadow_reports/incident_20261018_103012_ZeroDivisionError_9f2a1c4b.md:
# Shadow Debugger Incident Report
**Timestamp:** 2026-10-18T10:30:12.418290+00:00
**Exception:** `ZeroDivisionError`: division by zero
**Location:** `app/routes.py:42` in `checkout`
**Fingerprint:** `9f2a1c4b8e1032d1` (occurrences so far: 1)
---
### 1. Root Cause Summary
`checkout()` divides `50` by `discount_items` without checking for `0`. When the query parameter is omitted or set to `0`, Python raises `ZeroDivisionError`.
### 2. Trigger Condition
`GET /checkout/1042?discount_items=0` with local state `{"order_id": 1042, "discount_items": 0}`.
### 3. Proposed Fix
```python
unit_discount = 50 / discount_items if discount_items > 0 else 0.0
```
```diff
- unit_discount = 50 / discount_items
+ unit_discount = 50 / discount_items if discount_items > 0 else 0.0
```
### 4. Prevention Advice
Validate numeric query parameters with `Query(gt=0)` in FastAPI or guard denominators before dividing.
Installation
# Core package (stdlib only — works with local Ollama out of the box)
pip install shadow-debugger
# Or install with the provider / framework you use:
pip install "shadow-debugger[gemini]"
pip install "shadow-debugger[openai]"
pip install "shadow-debugger[anthropic]"
pip install "shadow-debugger[mistral]"
pip install "shadow-debugger[fastapi]"
pip install "shadow-debugger[flask]"
pip install "shadow-debugger[django]"
Quick start
Local with Ollama (no API key)
import shadow_debugger
shadow_debugger.init(
provider="ollama",
model="llama3.2",
print_to_console=True,
)
Cloud providers
import shadow_debugger
# Uses GEMINI_API_KEY
shadow_debugger.init(provider="gemini", model="gemini-3.8-flash")
# Uses OPENAI_API_KEY (or pass base_url=... for Groq / vLLM / LM Studio)
shadow_debugger.init(provider="openai", model="gpt-5.4-nano")
# Uses ANTHROPIC_API_KEY
shadow_debugger.init(provider="anthropic", model="claude-haiku-5-5")
# Uses MISTRAL_API_KEY
shadow_debugger.init(provider="mistral", model="mistral-small-latest")
Web frameworks
FastAPI / Starlette
from fastapi import FastAPI
import shadow_debugger
shadow_debugger.init(provider="ollama", model="llama3.2")
app = FastAPI()
app.add_middleware(shadow_debugger.FastAPIWatcherMiddleware)
Flask
from flask import Flask
import shadow_debugger
app = Flask(__name__)
shadow_debugger.init(provider="ollama", model="llama3.2")
shadow_debugger.init_flask(app)
init_flask hooks into got_request_exception, so normal 404/4xx responses are left untouched.
Django
In settings.py:
MIDDLEWARE = [
"shadow_debugger.integrations.DjangoWatcherMiddleware",
# ...
]
Decorator & manual capture
@watch works on both regular and async def functions:
import shadow_debugger
@shadow_debugger.watch(reraise=False)
async def process_order(payload: dict):
return payload["items"]["price"] / payload["items"]["quantity"]
# Or inside an existing try/except block:
try:
sync_inventory()
except Exception as exc:
shadow_debugger.capture_exception(exc, extra_metadata={"job": "inventory"})
Privacy & what gets sent
If you use a cloud provider, the prompt includes the traceback, the 5 lines of source around the error, and the local variables of the failing function. To keep sensitive data out of prompts:
- Variable & header names matching common secret names (
password,secret,token,api_key,authorization,cookie, etc.) are replaced with[REDACTED]. - String values matching JWTs, API keys (
sk-...,AIza...,AKIA...,ghp_...),Bearertokens, PEM private keys, and URL query tokens (?access_token=...) are scrubbed across variables, tracebacks, and exception messages. - Lazy objects (like Django
QuerySets) are inspected via__dict__without callingrepr()/str(), so capturing an error won't trigger extra database queries. - You can turn off parts of the payload with
send_locals=Falseorsend_source_code=False, add your own regexes viaredact_keys=[...]andredact_patterns=[...], or run everything locally withprovider="ollama". - Proposed code patches are only checked with
ast.parse()— generated code is never executed.
Configuration
All options can be passed to shadow_debugger.init(...):
| Option | Default | Description |
|---|---|---|
provider |
"gemini" |
"gemini", "ollama", "openai", "anthropic", "mistral", or a Provider instance. |
model |
None |
Model name. Uses the provider default if omitted. |
api_key |
None |
API key (falls back to GEMINI_API_KEY, OPENAI_API_KEY, ANTHROPIC_API_KEY, MISTRAL_API_KEY). |
base_url |
None |
Custom URL for Ollama (OLLAMA_HOST) or OpenAI-compatible servers. |
output_dir |
"./shadow_reports" |
Folder for reports (None disables file output). |
report_format |
"markdown" |
"markdown", "json", or "both". Paired reports use the same filename stem. |
print_to_console |
False |
Print diagnoses to stderr (handy in local dev). |
cooldown_seconds |
300.0 |
Minimum seconds before re-analyzing the same error at the same line. |
send_source_code |
True |
Include source lines around the crash. |
send_locals |
True |
Include redacted local variables. |
redact_keys |
() |
Extra regexes for variable/key names to redact. |
redact_patterns |
() |
Extra regexes for secret value patterns to scrub. |
request_timeout |
60.0 |
Timeout in seconds for LLM calls. |
shutdown_timeout |
10.0 |
Seconds to wait on process exit for pending reports to finish. |
max_queue_size |
100 |
Max queued incidents before dropping new ones. |
catch_uncaught |
True |
Hook sys.excepthook and threading.excepthook. |
JSON reports
Set report_format="json" for machine-readable reports, or report_format="both"
to keep Markdown and JSON side by side. Each JSON file contains:
{
"timestamp": "2026-10-18T10:30:12.418290+00:00",
"error_context": {
"exception_type": "ZeroDivisionError",
"exception_message": "division by zero",
"locals": {"order_id": 1042, "api_key": "[REDACTED]"}
},
"diagnosis": "### 1. Root Cause Summary\nDivision by zero."
}
error_context contains the full already-redacted incident payload, including
any captured locals, source context, metadata and traceback. It respects the
existing capture/privacy options; the serializer does not collect additional
data or redact caller-supplied contexts or diagnosis text. Nonfinite numbers
in the context become the strings "NaN", "Infinity", and "-Infinity" so
the file remains valid JSON. Diagnosis text is preserved exactly.
ReportManager.report() returns the JSON path in "json" mode, the Markdown
path in "both" mode, and None when file output is disabled. Existing
Markdown output remains the default.
CLI (list & show)
Inspect local Markdown reports from the terminal:
python -m shadow_debugger list
python -m shadow_debugger show latest
python -m shadow_debugger show <filename-or-fingerprint> --dir ./shadow_reports
Writing a custom provider
import shadow_debugger
from shadow_debugger import Provider, register_provider
@register_provider("my-gateway")
class MyGatewayProvider(Provider):
default_model = "my-model"
env_key = "MY_GATEWAY_KEY"
def complete(self, system: str, prompt: str) -> str:
self.check_configuration()
# Call your LLM endpoint and return Markdown
return "..."
shadow_debugger.init(provider="my-gateway")
Roadmap & contributing
I'm actively looking for feedback and contributors. A few areas where PRs are very welcome:
- Webhook / notification sinks (Slack, Discord, Telegram, GitHub Issues)
- Additional providers (Mistral added; LiteLLM, AWS Bedrock welcome)
- Structured JSON output option alongside Markdown reports
- Celery / background worker task integration
- CLI command to browse and filter local reports in
./shadow_reports
See CONTRIBUTING.md for local setup instructions.
License
Metadata
Release files for shadow-debugger 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Loss of provenance
These files do not have provenance metadata, despite files in a prior release including this data.
We recommend further investigation before installing these files. View details.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| shadow_debugger-0.2.0.tar.gz | 44.4 kB | Without provenance | Details for shadow_debugger-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| shadow_debugger-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for shadow_debugger-0.2.0-py3-none-any.whl |
Total release size: 81.9 kB
Release files / shadow_debugger-0.2.0.tar.gz
Loss of provenance
This file belongs to a release without provenance metadata, despite a prior release including this data.
We recommend further investigation before installing this file. View details.
| Download URL | shadow_debugger-0.2.0.tar.gz |
|---|---|
| Size | 44.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7258c66cf018d3b833eff307e9513d714a375bca4d0aa3355035e6293d831ce6
|
|
BLAKE2b-256 checksum How to use checksums |
a7495f8794a95003589155b731032bb9d430a19d15ca9b86acd50b598439225e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Release files / shadow_debugger-0.2.0-py3-none-any.whl
Loss of provenance
This file belongs to a release without provenance metadata, despite a prior release including this data.
We recommend further investigation before installing this file. View details.
| Download URL | shadow_debugger-0.2.0-py3-none-any.whl |
|---|---|
| Size | 37.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
33e93c09a3d3737620e113c9b31d698ef1f97e7783f8049c51449b2f4cf6974e
|
|
BLAKE2b-256 checksum How to use checksums |
f34b848143641d13341ce98f7f71063b33fc1f664c82f28b4107be5c8f4f3476
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Security for shadow-debugger 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Loss of provenance
A previous release of these files had provenance metadata, but this release does not.
While this could reflect a routine change by the project maintainers, it may also indicate that the release files have been compromised.
Release comparison
- Removed 0.1.0 2 files With provenance
- Added 0.2.0 2 files Without provenance
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.