TruthVouch Python SDK
Drop-in LLM governance for Python. Route OpenAI, Anthropic, and Google AI calls through the TruthVouch Governance Gateway for automatic policy enforcement, PII detection, and hallucination monitoring.
Installation
pip install truthvouch
Optional extras:
pip install "truthvouch[telemetry]" # OpenTelemetry + Prometheus
pip install "truthvouch[adapters]" # LangGraph + CrewAI integrations
pip install "truthvouch[all]" # Everything
Quick Start — Gateway Proxy
from truthvouch import TruthVouch
async with TruthVouch(gateway_url="https://gateway.truthvouch.com", api_key="tv_live_...") as client:
# OpenAI drop-in
resp = await client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "What is quantum computing?"}],
)
print(resp.choices[0].message.content)
print(resp.governance.verdict) # "allowed" | "blocked" | "flagged"
print(resp.governance.pii_detected) # False
Provider Facades
# Anthropic
resp = await client.anthropic.messages.create(
model="claude-3-5-sonnet-20241022",
messages=[{"role": "user", "content": "Hello"}],
max_tokens=512,
)
print(resp.text)
# Google AI
resp = await client.google.generate_content(
model="gemini-1.5-pro",
contents=[{"role": "user", "parts": [{"text": "Hello"}]}],
)
print(resp.text)
Streaming
async for chunk in await client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Tell me a story"}],
stream=True,
):
print(chunk.content, end="", flush=True)
if chunk.done:
print(f"\nVerdict: {chunk.governance_report.verdict}")
Batch Scanning
job = await client.batch.submit(source_url="s3://my-bucket/prompts.jsonl", format="jsonl")
status = await client.batch.get_status(job.id)
print(status.status) # "completed"
Governance Guards
For fine-grained input/output evaluation with local and remote guards:
from truthvouch.governance import GovernanceClient
client = GovernanceClient(api_key="vt_live_...")
result = client.evaluate_input("My SSN is 123-45-6789", model="gpt-4o")
if result.blocked:
print("Blocked:", result.block_reasons)
# Async usage
from truthvouch.governance import AsyncGovernanceClient
async with AsyncGovernanceClient(api_key="vt_live_...") as client:
result = await client.evaluate_input("Hello!", model="gpt-4o")
Built-in Guards
| Guard | Type | Description |
|---|---|---|
pii_regex |
Local | Regex PII detection (SSN, CC, email, phone, passport, address) |
banned_phrases |
Local | Case-insensitive banned phrase matching |
injection |
Local | 2-layer prompt injection heuristic detector |
cost |
Local | Token estimation + budget enforcement |
truth |
Remote | Truth nugget verification |
pii_remote |
Remote | Full Presidio PII scan |
Framework Adapters
LangGraph / LangChain:
from truthvouch.governance.adapters.langgraph import TruthVouchCallbackHandler
handler = TruthVouchCallbackHandler(client, model="gpt-4o")
result = chain.invoke(inputs, config={"callbacks": [handler]})
CrewAI:
from truthvouch.governance.adapters.crewai import TruthVouchMiddleware
middleware = TruthVouchMiddleware(client)
llm = middleware.wrap_llm(ChatOpenAI(model="gpt-4o"))
agent = Agent(llm=llm, role="Analyst", goal="...", backstory="...")
Error Handling
from truthvouch.exceptions import (
PolicyBlockedError,
AuthenticationError,
QuotaExceededError,
GatewayUnreachableError,
)
try:
resp = await client.chat.completions.create(model="gpt-4o", messages=[...])
except PolicyBlockedError as e:
print(f"Blocked: {e.governance_report}")
except AuthenticationError:
print("Invalid API key")
except QuotaExceededError as e:
print(f"Rate limited, retry after {e.retry_after_seconds}s")
except GatewayUnreachableError:
print("Gateway down — call went direct to LLM (fail-open mode)")
Configuration
from truthvouch import TruthVouch
client = TruthVouch(
gateway_url="https://gateway.truthvouch.com",
api_key="tv_live_...",
fail_mode="open", # "open" (bypass) or "closed" (raise error)
timeout=30.0, # HTTP timeout in seconds
max_retries=3, # Retry attempts with exponential backoff
circuit_breaker_threshold=5, # Failures before circuit opens
circuit_breaker_recovery_seconds=60, # Seconds before recovery probe
verify_ssl=True, # TLS certificate verification
)
License
Apache-2.0
Metadata
Release files for truthvouch 1.0.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 | Actions |
|---|---|---|---|---|
| truthvouch-1.0.0.tar.gz | 74.9 kB | Without provenance | Details for truthvouch-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| truthvouch-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for truthvouch-1.0.0-py3-none-any.whl |
Total release size: 145.2 kB
Release files / truthvouch-1.0.0.tar.gz
| Download URL | truthvouch-1.0.0.tar.gz |
|---|---|
| Size | 74.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c1f52afb4725e1ab1409fbcde313254023e8b093e6d5379e5cca2107967d74e5
|
|
BLAKE2b-256 checksum How to use checksums |
106e8c5f6e864bd5db788662092675d56e5410bc8ec87d10e86e97f6ce5445ec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / truthvouch-1.0.0-py3-none-any.whl
| Download URL | truthvouch-1.0.0-py3-none-any.whl |
|---|---|
| Size | 70.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b58ed15de198a81af2144ea8f9bfc6977851a657df465a6963e871bd10df6016
|
|
BLAKE2b-256 checksum How to use checksums |
e8f6312f1c861f362e3649190eb5f452bd553b0605462268502a71834a4be888
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for truthvouch 1.0.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.