Skip to main content

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.

Agent Assurance

The SDK includes a separate AssuranceClient for reviewed agent checks: create a run, read JSON evidence and wait for its terminal result. It uses a dedicated project-scoped Assurance CI key, never retries run creation, and has no fail-open fallback. Baselines, repeated trials and ordered conversation evidence use the same backend contracts as the console. Human release decisions remain in the console. See Agent Assurance setup and examples. Version 1.29.7 validates scenario totals and outcomes before accepting a passing result. Setup instructions and CI examples are in the guide.

Release clearance

SDK 1.30.0 adds deployment preflights and release identity for live guarded actions. Use one reviewed clearance at both boundaries, bind application keys in the console, and enable required-clearance operation to withhold dispatch on outages or missing evidence. Deployment keys are separate from live keys. See release clearance setup and examples.

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

Response adapters apply DG's decision before returning text. Deliver their return value, not the original model output. A sanitized response may legitimately be an empty string; missing or non-string replacement text raises even in fallback mode. Strands also raises if an event cannot apply the replacement or cancel a blocked tool. Use fail_open=False to stop when DG is unavailable, and do not stream unchecked text before the response hook completes.

Documentation

Requirements

  • Python 3.8+
  • DriftGard API key
  • DriftGard project ID

License

MIT

Metadata

Release files for driftgard 1.31.0

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

Source distribution (sdist)

Source distribution for driftgard 1.31.0
File Size Uploaded Provenance Actions
driftgard-1.31.0.tar.gz 532.0 kB Without provenance Details for driftgard-1.31.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for driftgard 1.31.0
File Interpreter ABI Platform Actions
driftgard-1.31.0-py3-none-any.whl Python 3 none any Details for driftgard-1.31.0-py3-none-any.whl

Total release size: 1.0 MB

Release files / driftgard-1.31.0.tar.gz

Download URL driftgard-1.31.0.tar.gz
Size 532.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8fc637227825548d08a5b33527e0adb4ad36ff4c45db601c1821f023ad3bf19a
BLAKE2b-256 checksum
How to use checksums
19ff3f1bf618d073a1a07c1a773d219e3fed8bcf200daba316504d95d40bbaf4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release files / driftgard-1.31.0-py3-none-any.whl

Download URL driftgard-1.31.0-py3-none-any.whl
Size 503.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2b294b42e824ff325ab749944be1f9ebd80a4aee8280a655c18a8ca0fe0b7152
BLAKE2b-256 checksum
How to use checksums
30220a523f7d080a49404eae2acea4f4c94ec862b1300d4ad3f92182a3a36d42
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Security for driftgard 1.31.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.

Release history Release notifications | RSS feed

This release

1.31.0 This release

2 release files No provenance

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