Skip to main content

Veridian Guard 🛡️

Robust retry and fallback decorators for unpredictable AI agents, LLM calls, and flaky network requests.

When your AI agents crashes, the API rate limits you, or a network request fails, Veridian Guard gracefully catches the errors, retries the execution with custom delays, and provides safe fallbacks to prevent production crashes.


🚀 Installation

pip install veridian-guard

⚡ Quick Start (Sync)

Wrap any flaky function like an LLM API call with the @guard decorator:

from veridian_guard import guard
import random

@guard(max_retries=3, delay=1.5, fallback="Default safe response")
def call_llm_agent():
    # Simulating a random API failure
    if random.random() < 0.7:
        raise ConnectionError("LLM API Timeout!")
    return "Agent succeeded! Here is your generated text."

result = call_llm_agent()
print(result)

🔄 Async/Await Support Built-in

Veridian Guard automatically detects whether your function is synchronous or asynchronous. It works flawlessly with async/await, making it perfect for modern AI agent chains or Crew AI.

import asyncio
from veridian_guard import guard

@guard(max_retries=3, delay=2.0, fallback="Failed", async_def_fetch_data_from_llm=True)
async def fetch_data_from_llm():
    # Simulating a heavy async API call
    await asyncio.sleep(1)
    raise TimeoutError("API is too busy")

async def main():
    result = await fetch_data_from_llm()
    print(result)  # Will print the fallback: "Failed"

asyncio.run(main())

✨ Why Veridian Guard?

✅ Zero Dependencies - Pure Python, Extremely lightweight.

✅ Smart Logging Built-in - Automatically logs failed attempts and warnings so you can monitor your agent's behavior in the terminal.

✅ Fail-Safe Fallbacks - Never let an unhandled exception crash your main application loop again.

✅ Universal - Seamlessly handles both def and async def functions out of the box.


🔧 Advanced Usage

Catching specific exceptions instead of all errors:

from veridian_guard import guard

@guard(
    max_retries=5,
    delay=2.5,
    exceptions=(TimeoutError, ConnectionError)
)
def call_data():
    # Will only retry on TimeoutError or ConnectionError
    # Other exceptions like ValueError will be raised immediately
    pass

📦 Parameters

Parameter Type Default Description
max_retries int 3 Maximum number of retry attempts
delay float 1.0 Delay in seconds between retries
fallback any None Value to return if all retries fail
exceptions tuple (Exception,) Specific exceptions to catch and retry

📝 Real-World Use Cases

1. LLM API Calls

@guard(max_retries=5, delay=2.0, fallback="Sorry, AI is unavailable")
def ask_chatgpt(prompt):
    return openai.ChatCompletion.create(...)

2. Database Connections

@guard(max_retries=3, delay=1.0, exceptions=(ConnectionError,))
def connect_to_db():
    return psycopg2.connect(...)

3. Web Scraping

@guard(max_retries=4, delay=3.0, fallback=[])
def scrape_website(url):
    response = requests.get(url, timeout=5)
    return response.json()

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.


📄 License

MIT License - feel free to use in your projects!


🌟 Star Us!

If Veridian Guard helped you build more resilient AI agents, give us a star on GitHub! ⭐


Made with 💚 for the AI Agent community

Metadata

Release files for veridian-guard 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for veridian-guard 0.2.2
File Size Uploaded Provenance
veridian_guard-0.2.2.tar.gz 4.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for veridian-guard 0.2.2
File Interpreter ABI Platform
veridian_guard-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 9.0 kB

Release files / veridian_guard-0.2.2.tar.gz

Download URL veridian_guard-0.2.2.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7ce960bb31e74030761822bd9063b27f45baccc0ebbc5efea884d712aa62e69d
BLAKE2b-256 checksum
How to use checksums
9b76eb8940e23e216b12aca4978c2bdff3f5eab59655cc340967bb0a1bcc274b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Release files / veridian_guard-0.2.2-py3-none-any.whl

Download URL veridian_guard-0.2.2-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e488112acc53568f49c158191f8f20a20f5fb1c7be3f6ae383ea7ae5118d67f2
BLAKE2b-256 checksum
How to use checksums
efbb6b8f3af45ad79025f42920add82799b702f5e686cde853b6c7191641aca0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Security for veridian-guard 0.2.2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page