Self-healing API proxy for AI agents. Route your HTTP calls through Graceful Fail and get structured, LLM-powered fix instructions when APIs return errors.
Project description
graceful-fail
Self-healing API proxy for AI agents. Route your HTTP calls through Graceful Fail and get structured, LLM-powered fix instructions when APIs return errors.
Instead of your agent crashing on a 422 or retrying a 503 blindly, it gets back:
{
"is_retriable": false,
"actionable_fix_for_agent": "Remove 'name' field. Add 'first_name' and 'last_name' as separate string fields.",
"suggested_payload_diff": {
"remove": ["name"],
"add": {"first_name": "string", "last_name": "string"}
},
"error_category": "validation_error"
}
Successful requests (2xx/3xx) pass through with zero overhead. You only pay when the LLM is invoked on a failed request.
Install
pip install graceful-fail
With LangChain support:
pip install 'graceful-fail[langchain]'
Quick Start
from graceful_fail import GracefulFail
gf = GracefulFail(api_key="gf_your_key")
response = gf.post("https://api.example.com/users", json={"name": "Alice"})
if response.intercepted:
# The API returned an error — here's exactly how to fix it
print(response.error_analysis.actionable_fix_for_agent)
print(response.error_analysis.suggested_payload_diff)
else:
# Success — here's the data
print(response.data)
Async Support
from graceful_fail import GracefulFailAsync
async with GracefulFailAsync(api_key="gf_your_key") as gf:
response = await gf.post("https://api.example.com/users", json={"name": "Alice"})
LangChain Integration
As a Tool (recommended for agents)
from graceful_fail.langchain import GracefulFailTool
from langchain.agents import create_react_agent
tool = GracefulFailTool(api_key="gf_your_key")
agent = create_react_agent(llm, [tool])
# Your agent now gets structured fix instructions instead of raw HTTP errors
As a Requests Wrapper
Drop-in replacement for LangChain's TextRequestsWrapper:
from graceful_fail.langchain import GracefulFailRequests
requests = GracefulFailRequests(api_key="gf_your_key")
result = requests.get("https://api.example.com/users")
requests-Compatible Session
For codebases already using requests:
from graceful_fail.patch import GracefulFailSession
session = GracefulFailSession(api_key="gf_your_key")
resp = session.post("https://api.example.com/users", json={"name": "Alice"})
print(resp.status_code)
print(resp.json())
if resp.graceful_fail_intercepted:
print(resp.error_analysis)
Response Object
Every call returns a GracefulFailResponse:
| Field | Type | Description |
|---|---|---|
status_code |
int |
HTTP status from the destination API |
intercepted |
bool |
True if the error was analyzed by the LLM |
data |
Any |
Response body (success) or full error envelope (intercepted) |
error_analysis |
ErrorAnalysis |
LLM analysis (only when intercepted=True) |
raw_response |
Any |
Original destination API response body |
credits_used |
int |
0 for pass-through, 1 for intercepted |
ErrorAnalysis Fields
| Field | Type | Description |
|---|---|---|
is_retriable |
bool |
Whether retrying the same request may succeed |
human_readable_explanation |
str |
What went wrong, in plain English |
actionable_fix_for_agent |
str |
Exact instruction for the agent |
suggested_payload_diff |
PayloadDiff |
What to change (remove/add/modify) |
error_category |
str |
validation_error, auth_error, rate_limit, etc. |
Auto-Apply Fix
if response.intercepted:
fixed_payload = response.error_analysis.suggested_payload_diff.apply(original_payload)
retry_response = gf.post(url, json=fixed_payload)
Get Your API Key
- Sign up at selfheal.dev
- Create an API key in the dashboard
- Free tier: 500 requests/month
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file graceful_fail-0.3.0.tar.gz.
File metadata
- Download URL: graceful_fail-0.3.0.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d01899f9ffd8a42bff3a855ecbab8ec31f592db9b49d73266dfb47d640db56bc
|
|
| MD5 |
04d325bd1c965ba13424822cc75dd600
|
|
| BLAKE2b-256 |
3112e6da83fecaae208d32f1aa519d7b6e7a13714eb749d6ba63837222a45581
|
Provenance
The following attestation bundles were made for graceful_fail-0.3.0.tar.gz:
Publisher:
publish-pypi.yml on carsonlabs/graceful-fail
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
graceful_fail-0.3.0.tar.gz -
Subject digest:
d01899f9ffd8a42bff3a855ecbab8ec31f592db9b49d73266dfb47d640db56bc - Sigstore transparency entry: 1199315497
- Sigstore integration time:
-
Permalink:
carsonlabs/graceful-fail@f8603116423e7a664344212e73c16ce696a8aa0f -
Branch / Tag:
refs/heads/main - Owner: https://github.com/carsonlabs
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@f8603116423e7a664344212e73c16ce696a8aa0f -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file graceful_fail-0.3.0-py3-none-any.whl.
File metadata
- Download URL: graceful_fail-0.3.0-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d90340bc94338326d342a25c4613dfb379cc6962593b4126752b6d8f78b8c52
|
|
| MD5 |
20ce3d5b869b7f072b3ba58cc541590f
|
|
| BLAKE2b-256 |
3cb71885fb888c11fc823b37fb1c50f954cae032d5f155be9c57145d7f8c25f9
|
Provenance
The following attestation bundles were made for graceful_fail-0.3.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on carsonlabs/graceful-fail
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
graceful_fail-0.3.0-py3-none-any.whl -
Subject digest:
2d90340bc94338326d342a25c4613dfb379cc6962593b4126752b6d8f78b8c52 - Sigstore transparency entry: 1199315506
- Sigstore integration time:
-
Permalink:
carsonlabs/graceful-fail@f8603116423e7a664344212e73c16ce696a8aa0f -
Branch / Tag:
refs/heads/main - Owner: https://github.com/carsonlabs
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@f8603116423e7a664344212e73c16ce696a8aa0f -
Trigger Event:
workflow_dispatch
-
Statement type: