agentguard
Official Python SDK for AgentGuard — the AI action firewall that keeps your agents safe.
Install
pip install agentguard
Requirements: Python 3.8 or later.
Quick Start
from agentguard import AgentGuard
guard = AgentGuard(api_key="ag_live_YOUR_KEY_HERE")
Then, before your agent executes any action:
result = guard.check(
action="send_email",
payload={"to": "user@example.com", "body": "Hello!"},
)
if result.decision == "block":
raise Exception(f"Action blocked: {result.reason}")
# proceed with the action
Constructor Options
AgentGuard(
api_key: str, # required — from your AgentGuard dashboard
base_url: str = None, # default: https://agentguard.dev/api
# also read from AGENTGUARD_BASE_URL env var
timeout: float = 5.0, # request timeout in seconds
)
The base_url is resolved in this order:
base_urlargument passed to the constructorAGENTGUARD_BASE_URLenvironment variablehttps://agentguard.dev/api(production default)
guard.check() Reference
result = guard.check(
action: str, # required — name of the action
payload: dict, # required — data the agent is acting on
agent_id: str | None = None, # which agent is acting (improves logging)
app_user_id: str | None = None, # end user ID (enables cross-user detection)
app_name: str | None = None, # identifies your app in the dashboard
risk_context: dict | None = None, # extra metadata for risk scoring
)
Return value — CheckResult
@dataclass
class CheckResult:
decision: Literal["allow", "block", "review"]
risk_level: Literal["low", "medium", "high", "critical"]
reason: str
log_id: int | None
prompt_injection_detected: bool
Handling Each Decision
result = guard.check(action=action, payload=payload)
if result.decision == "allow":
# Safe to proceed. Execute the action.
execute_action(action, payload)
elif result.decision == "review":
# High-risk but not definitively malicious.
# Queue for human review or notify your security team.
queue_for_review(action, payload, result.reason)
elif result.decision == "block":
# Policy violation or detected threat. Do NOT proceed.
raise Exception(f"Blocked ({result.risk_level}): {result.reason}")
Error Handling
from agentguard import (
AgentGuard,
AgentGuardAuthError,
AgentGuardNetworkError,
AgentGuardServerError,
)
try:
result = guard.check(action=action, payload=payload)
except AgentGuardAuthError as e:
# Invalid or expired API key — check your dashboard
print(f"Auth error: {e}")
except AgentGuardNetworkError as e:
# Connectivity issue — the SDK already retried once
# Fall back gracefully (allow or queue for later)
print(f"Network error: {e}")
except AgentGuardServerError as e:
# Unexpected server error (5xx)
print(f"Server error {e.status_code}: {e}")
The SDK automatically retries once on network errors. Auth errors and server errors are never retried.
Example — Flask Route
from flask import Flask, request, jsonify
from agentguard import AgentGuard
import os
guard = AgentGuard(api_key=os.environ["AGENTGUARD_KEY"])
app = Flask(__name__)
@app.post("/agent/send-email")
def send_email():
data = request.get_json()
result = guard.check(
action="send_email",
payload={"to": data["to"], "body": data["body"]},
app_user_id=data.get("userId"),
agent_id=data.get("agentId"),
)
if result.decision == "block":
return jsonify({"error": result.reason}), 403
# send the email...
return jsonify({"ok": True})
Publishing to PyPI
When you're ready to publish:
cd sdks/python
pip install build twine
python -m build
twine upload dist/*
Make sure your pyproject.toml has the correct name, version, and license fields before publishing.
Links
- Dashboard — manage API keys and view logs
- API Reference — raw HTTP API docs
- GitHub — source code and issues
Metadata
Release files for aguard 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| aguard-0.1.0.tar.gz | 7.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aguard-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.4 kB
Release files / aguard-0.1.0.tar.gz
| Download URL | aguard-0.1.0.tar.gz |
|---|---|
| Size | 7.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2de5b9a3b928c0f33669f47df8e7110334e4434b17ce9fff1fe739ee31223ff7
|
|
BLAKE2b-256 checksum How to use checksums |
79126e069082e467f44558ba87234ab1d54e76b7499c344f40358fb63c419fdf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Release files / aguard-0.1.0-py3-none-any.whl
| Download URL | aguard-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5bfad43597f79cc9b980e7ec66fbf77e18d59b70def03729c742abca5ad3739c
|
|
BLAKE2b-256 checksum How to use checksums |
998cf37d9bd839c61333c96fd556040b40ca5ec5f509cadd8a58aaccb7b8b0f7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Security for aguard 0.1.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.
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.