Skip to main content

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

  1. Sign up at selfheal.dev
  2. Create an API key in the dashboard
  3. Free tier: 500 requests/month

Links

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

graceful_fail-0.1.0.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

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

graceful_fail-0.1.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file graceful_fail-0.1.0.tar.gz.

File metadata

  • Download URL: graceful_fail-0.1.0.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for graceful_fail-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f3bd0665fe88b899d0330be0ac689a40de1d33e591f48c7c2bb29b74b4e428c7
MD5 f30318590c5ed60eed2da219c0fab3f4
BLAKE2b-256 37932d66ba3783843bef59288f2730848262b61042aa9e825ccd1acbcebac342

See more details on using hashes here.

File details

Details for the file graceful_fail-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: graceful_fail-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for graceful_fail-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 74ef846851ddeafb8ffdaad95daf61411df5c7cb9b0d4dfaea6d0ce246491224
MD5 60507d8922236106754a188f2dcd989c
BLAKE2b-256 7cddbdd9a74b9c1650c0365069a15631625a27198e63530fddcd76a8051b8318

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