driftgard
Official Python SDK for DriftGard.
Use it to control what production AI can say and do: evaluate prompts and responses, run OpenAI-compatible gateway calls through DriftGard, validate agent tool calls, and record audit evidence.
Install
pip install driftgard
Requires Python 3.8 or newer.
Quick Start
from driftgard import Driftgard
dg = Driftgard(api_key="dg_...")
result = dg.evaluate(
project_id="proj_...",
prompt="What stocks should I buy?",
response="You should invest everything in...",
model_id="gpt-4o",
)
if not result["evaluation"]["allowed"]:
print("Blocked:", result.get("fallback", {}).get("message"))
elif result["evaluation"].get("sanitized"):
print("Use sanitized response:", result["evaluation"]["sanitized_response"])
else:
print("Allowed")
Inline Gateway
Use the gateway when DriftGard should sit in the request path, call the provider, enforce policy, and return the final response.
completion = dg.gateway_chat_completions(
project_id="proj_...",
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "You are a support assistant."},
{"role": "user", "content": "Summarize the refund process."},
],
driftgard={
"gateway_mode": "enforce",
"agent_id": "support-agent",
"agent_role": "customer_support",
"session_id": "sess_123",
},
)
print(completion["choices"][0]["message"]["content"])
print(completion.get("driftgard", {}).get("gateway_decision"))
Streaming is also supported:
stream = dg.stream_gateway_chat_completions(
project_id="proj_...",
model="gpt-4o-mini",
messages=messages,
driftgard={"gateway_mode": "observe"},
)
Tool Call Validation
Validate agent tool calls against Control Pack tool_rules.
result = dg.evaluate(
project_id="proj_...",
eval_mode="tool_call",
tool_call={
"tool_name": "transfer_money",
"parameters": {"amount": 500, "to_account": "acct_123"},
},
agent_role="payments_agent",
model_id="agent-runtime",
)
if not result["evaluation"]["allowed"]:
raise RuntimeError(result.get("fallback", {}).get("message", "Tool call blocked"))
Local Evaluation
For sensitive environments, the SDK can evaluate locally through DriftGard's WASM evaluator.
dg = Driftgard(
api_key="dg_...",
mode="local",
project_id="proj_...",
)
dg.init()
result = dg.evaluate(prompt=prompt, response=response, model_id="local-model")
Modes:
| Mode | Behavior |
|---|---|
remote |
Send prompt/response to DriftGard API |
local |
Evaluate locally; no prompt/response leaves your environment |
local-with-audit |
Evaluate locally and report verdict metadata only |
Framework Integrations
Included integrations:
- LangChain response guardrail
- LangChain tool guard
- CrewAI response and tool guardrails
- Strands / AWS Agent Core hook
- local semantic matching for local mode
Documentation
- Gateway
- Tool calls
- Local evaluation
- Governed Knowledge
- Configuration and failure modes
- Framework integrations
Requirements
- Python 3.8+
- DriftGard API key
- DriftGard project ID
License
MIT
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 driftgard-1.29.0.tar.gz.
File metadata
- Download URL: driftgard-1.29.0.tar.gz
- Upload date:
- Size: 500.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
639e2d2d38410adb82a2ccfd654f959a0883d7bf61cda61ef1d44cf91dfa1556
|
|
| MD5 |
29616525e05a31eebff2cd5576e2f028
|
|
| BLAKE2b-256 |
30caed4288d8dfe927a27ace83acd72f9e366f18edf2c396d09453a63d3ac847
|
File details
Details for the file driftgard-1.29.0-py3-none-any.whl.
File metadata
- Download URL: driftgard-1.29.0-py3-none-any.whl
- Upload date:
- Size: 490.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a00e56ae4dcb2ce9b4a05b86487171a690a83472a9f169ada1789926532c7514
|
|
| MD5 |
c31d4c725305b39fe4011068a452c133
|
|
| BLAKE2b-256 |
36a5c63b258d4cac7e0f2ae45f9679b2e5eb50a2cb29fb118f25a70842bd5341
|