Python SDK
The reference implementation: client, guard decorator, framework middleware, and provider interceptors.
Install
Python
pip install veldrixai
Client
Python
import veldrixai
# Explicit key
client = veldrixai.Veldrix(api_key="vx-live-...")
# Or from the environment (VELDRIX_API_KEY)
client = veldrixai.Veldrix.from_env()
# Options
client = veldrixai.Veldrix(
api_key="vx-live-...",
base_url="https://api.veldrixai.ca", # default
background=True, # async by default
)
Evaluate
Python
# Synchronous
result = client.evaluate_sync(prompt=p, response=r, metadata={"context": docs})
# Async
result = await client.evaluate(prompt=p, response=r)
result.overall # 0.0–1.0
result.verdict # ALLOW | WARN | REVIEW | BLOCK
result.pillar_scores # {"safety": 0.97, ...}
result.critical_flags # ["pii_detected", ...]
Guard decorator
Wrap any function returning model text. Background by default; opt into blocking per verdict.
Python
from veldrixai import Veldrix, GuardConfig
veldrix = Veldrix(api_key="vx-live-...")
@veldrix.guard(config=GuardConfig(
background=False, # block until evaluated
block_on_verdict=["BLOCK"], # raise VeldrixBlocked on these verdicts
timeout_ms=10_000,
))
def answer(prompt: str) -> str:
return llm.complete(prompt)
Web middleware
Drop-in middleware for FastAPI and Flask evaluates responses centrally:
Python
from veldrixai import VeldrixMiddleware, init_flask
# FastAPI
app.add_middleware(VeldrixMiddleware, api_key="vx-live-...")
# Flask
init_flask(app, api_key="vx-live-...")
Error handling
| Exception | Raised when |
|---|---|
VeldrixBlocked | A guarded call returns a verdict in block_on_verdict. |
VeldrixAuthError | The API key is missing, malformed, or revoked. |
VeldrixTimeout | Evaluation exceeded timeout_ms. |
In background mode the SDK never blocks your LLM path — if VeldrixAI is unreachable, your app keeps serving and the evaluation is retried/logged out of band (fail-open by design).
Was this page helpful?