Lightweight guard layer for AI agents — retry, catch, log.
Project description
Veridian Guard 🌿
Robust retry and fallback decorators for unpredictable AI agents, LLM calls, and flaky network requests.
When your AI agent 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
Example: An unpredictable LLM function
@guard(max_retries=3, delay=1.0, 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 asyncio, making it perfect for modern AI agents like LangChain or CrewAI.
import asyncio from veridian.guard import guard
@guard(max_retries=3, delay=2.0, fallback={"status": "failed"}) 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: {'status': '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.0, exceptions=(TimeoutError, ConnectionError)) def fetch_data(): # Will only retry on TimeoutError or ConnectionError. # Other exceptions (like ValueError) will be raised immediately. pass
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
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 veridian_guard-0.2.0.tar.gz.
File metadata
- Download URL: veridian_guard-0.2.0.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3bf1ccc31d0e3c1960fec280feac8237d6c9c16e7cb7c9d9104f7990b4200730
|
|
| MD5 |
c903aa747701f632c3eb36242efe5eb8
|
|
| BLAKE2b-256 |
048a1d71d761d6bf711824a7f434ab252fe0d0e5e2a7db9f515ac02267fce9e2
|
File details
Details for the file veridian_guard-0.2.0-py3-none-any.whl.
File metadata
- Download URL: veridian_guard-0.2.0-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b8854d764dd1dd7cba6637f18149715d4ea406bb3dd602ba8b8ec7875d921b9
|
|
| MD5 |
3e53ded2e69fa7a20ce55629b15225e6
|
|
| BLAKE2b-256 |
1beb63b0680ea9096f5323b90068966ddde5747906fa996de3e3b5358bbdc188
|