Skip to main content

valguard-sdk (Python)

Thin Python helpers for the ValGuard OpenAI-compatible integrity layer.

Package name: valguard-sdk. pip install valguard installs an unrelated third-party project. Import this SDK as valguard.

Public GitHub: github.com/valguard-ai/sdk-python.

Set VG_PROXY to your layer URL — see valguard.ai/docs/quickstart.

Install

pip install valguard-sdk
# or, from this repo: pip install "git+https://github.com/valguard-ai/sdk-python.git"
pip install openai   # optional, for OpenAI SDK bridge

Environment

export VG_PROXY="https://api.valguard.ai"   # your layer base URL
export VG_API_KEY="vg_live_..."
export VG_AGENT="invoice_extraction_agent"
export VG_PROVIDER_KEY="sk-..."             # optional BYOK upstream key

with_agent and with_playbook

with_agent sets X-VG-Agent. with_playbook sets X-VG-Flow. Pass provider_key (or VG_PROVIDER_KEY via from_env) so openai_client_kwargs() includes X-Provider-Key.

vg = ValGuardClient.from_env().with_playbook("invoice-processing")
from openai import OpenAI
from valguard import ValGuardClient

vg = ValGuardClient.from_env()
client = OpenAI(**vg.openai_client_kwargs())

raw = client.with_raw_response.chat.completions.create(
    model="openai/gpt-4o-mini",
    messages=[{"role": "user", "content": "Extract invoice JSON"}],
)

print(vg.parse_response_headers(dict(raw.http_response.headers)))
print(raw.parse())

Stdlib-only HTTP

from valguard import ValGuardClient

vg = ValGuardClient(
    api_key="vg_live_...",
    base_url="https://api.valguard.ai",
    agent_slug="default",
    provider_key="sk-...",
)

result = vg.chat_completions(
    model="openai/gpt-4o-mini",
    messages=[{"role": "user", "content": "hi"}],
)
print(result.validation)
print(result.data)

RAG sources

vg = ValGuardClient.from_env().with_rag_sources(
    [{"id": "doc-1", "text": "Acme revenue was $4.2M in Q3."}]
)

Errors

from valguard import ValGuardClient, ValGuardError

try:
    vg.chat_completions(model="openai/gpt-4o-mini", messages=[])
except ValGuardError as err:
    print(err.info.type)  # validation_block, input_validation, rate_limit_exceeded, ...

Soft-fail agents return HTTP 200 with valid: false — inspect result.error.soft_fail instead of exceptions.

API surface

Symbol Purpose
ValGuardClient Main client + from_env()
openai_client_kwargs() Legacy functional helper
parse_validation_headers() Read X-VG-* headers, including repair, cache, trace, and approval
verify_proof() / verify_evidence() Offline HMAC check of a Proof download (valguard-evidence/1)
parse_valguard_error() Parse error / soft-fail JSON
ValGuardError Raised on non-2xx responses

with_approval_mode("async") sends X-VG-Approval-Mode. with_idempotency_key sends X-VG-Idempotency-Key. with_trace sends traceparent, X-VG-Parent-Span-Id, and X-VG-Agent-Id. Response repair is reported with X-VG-Healed, X-VG-Healed-Rules, X-VG-Healed-Event-Count, and X-VG-Healed-Trace. Presets are agent settings.

Metadata

Release files for valguard-sdk 0.3.1

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

Source distribution (sdist)

Source distribution for valguard-sdk 0.3.1
File Size Uploaded
valguard_sdk-0.3.1.tar.gz 13.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for valguard-sdk 0.3.1
File Interpreter ABI Platform
valguard_sdk-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 24.3 kB

Release files / valguard_sdk-0.3.1.tar.gz

Download URL valguard_sdk-0.3.1.tar.gz
Size 13.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e3fb6c8ba222697be2528ac1c2ee09a47f44eafc06b8a6145e25ce25be3073e5
BLAKE2b-256 checksum
How to use checksums
38f30dbce5c50a43ece7cfbebb981b99321c6ead6000f30b7fe2ade619b324d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Release files / valguard_sdk-0.3.1-py3-none-any.whl

Download URL valguard_sdk-0.3.1-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2d4d9d9091cec171907d63abb972b97892b8fcfa6669d9b608ef77d8a4eb23ea
BLAKE2b-256 checksum
How to use checksums
93c0c1500b50d68e82cde1dd70b614a5c40183d7825289fa730ab3ea24b95a9e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

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