Python SDK
Use veriproof-sdk for application-owned actions. Add an Enforce adapter when you need policy checks at a supported framework boundary.
Govern one action
Use Python 3.11, 3.12, or 3.13. This example needs only the core package.
In the customer portal, open Tools and SDKs. Select your language and adapters, then follow the installation instructions shown there.
The package registry instructions use VeriProof's public GitLab feeds. Installs require no GitLab account or package credential. See SDK access for workstation and CI guidance.
VeriProof packages used here: veriproof-sdk.
Set VERIPROOF_API_KEY in the environment where you run Python. Use the SDK key for your application. The SDK defaults to https://ingest.veriproof.app. For VeriProof Private, set VERIPROOF_ENDPOINT to your ingest API base URL.
Save this example as quickstart.py. It returns a fictional payment record.
import asyncio
from veriproof_sdk import GovernedActionContext, Veriproof
async def pay_claim(context: GovernedActionContext) -> dict:
# Your business logic. It runs only when policy allows the action.
return {"paymentId": "PAY-1", "claimId": context.input["claim_id"]}
async def main() -> None:
claim = {"claim_id": "CLM-4417", "amount": 1250}
vp = Veriproof.from_env()
try:
result = await vp.govern(
"claims.pay",
claim,
pay_claim,
facts={"claim_amount": claim["amount"]},
)
finally:
await vp.shutdown()
if result.completed:
print(result.value)
else:
print(result.status.value, result.reason_code, result.message)
if result.session_id:
print(f"Session ID: {result.session_id}")
asyncio.run(main())Run python quickstart.py in the same environment where you installed the SDK. When policy allows the sample action, it prints a record containing PAY-1 and CLM-4417. Open your application in the customer portal and find the printed session ID under Sessions.
govern is async, so call it from async code. shutdown() sends any evidence the SDK kept during an outage, then closes the client. It raises if some evidence couldn’t be delivered. async with Veriproof.from_env() as vp: also closes the client, but doesn’t send kept evidence.
Each govern() call records its own session. The SDK creates a new session ID for every call unless you pass session_id=, and a session ID you pass must not be reused. To connect the steps of one conversation, pass the same session_context=SessionContext(external_reference="...") on each call. Each step stays a separate session, and the portal shows the shared reference on each one.
The core SDK checks the input before it calls pay_claim. It checks output before release through the typed result.value boundary.
Only completed, completed_with_warning, and transformed carry a released value. When policy stops the action the status is blocked, which the portal shows as Stopped by policy. A stopped input never calls the protected action, and a stopped output never reaches the caller.
Never release a value from a blocked result. Use result.status, result.message, result.reason_code, and result.evidence_reference to handle results without a value.
A review_context_required result means policy asked for human review, but the call didn’t include review options, so no review was opened. VeriProof recorded the attempt. Add review=GovernReviewOptions(...) with an active review profile and run the action again.
result carries no top-level decision ID. Read it from result.decision.decision_id, which is set when a rule decided the outcome, and read the session from result.session_id. See Rate a session result for every status.
Run a LangGraph workflow from FastAPI
The runnable Python example serves a shipment lookup agent through FastAPI. LangChain builds the agent as a LangGraph workflow with a scripted model and one local tool. You need a VeriProof application SDK key for this example. The scripted model runs without a model-provider account.
Create the application and key
Sign in with the VeriProof CLI and run veriproof auth status to confirm your organization. Use a Development application. The explicit environment flag works with CLI 1.0.3 and later.
veriproof apps create "Python Shipment Support Agent" --environment development
read -rp 'Application ID: ' APP_ID
veriproof keys create "$APP_ID"Paste the application ID from the first command at the prompt. Copy the SDK key when it appears. Set it in the shell where you will run the agent, using a secret store or a hidden prompt.
read -rsp 'Application SDK key: ' VERIPROOF_API_KEY; printf '\n'
export VERIPROOF_API_KEYInstall and run the agent
In a Python 3.11–3.13 virtual environment, download the example and the Core wheel. pip downloads VeriProof wheels from GitLab and resolves public dependencies separately. Package downloads require no CLI sign-in.
Check python --version in your active environment. If your workstation defaults to Python 3.14 or another unsupported version, create a new environment with Python 3.12. For example, with uv installed , run uv venv --seed --python 3.12 .venv. In Bash, activate it with source .venv/bin/activate.
curl -fL https://docs.veriproof.app/downloads/fastapi_langgraph_agent.py -o fastapi_langgraph_agent.py
feed=https://gitlab.com/api/v4/projects/84586136/packages/pypi/simple
wheels=$(mktemp -d)
python -m pip download --no-deps --only-binary=:all: \
--index-url "$feed" --dest "$wheels" veriproof-sdk==1.2.0
python -m pip install "$wheels/veriproof_sdk-1.2.0-py3-none-any.whl" \
fastapi==0.165.0 uvicorn==0.55.0 langchain==1.4.5 langgraph==1.2.11
python -m uvicorn fastapi_langgraph_agent:app --host 127.0.0.1 --port 8000From another terminal, call the agent and open the returned session_id using the CLI.
curl -fsS http://127.0.0.1:8000/run -H 'Content-Type: application/json' \
-d '{"shipment_id":"SHIP-1042"}'
printf '\n'
read -rp 'Session ID: ' SESSION_ID
veriproof sessions get "$SESSION_ID"The example returns In transit and records a shipment.lookup session. Set SESSION_ID to the ID from the response. FastAPI initializes one SDK client per worker in its lifespan handler. The route calls agent.ainvoke() inside govern() and releases the result when policy allows it. A Deny returns HTTP 403 with the session ID. The sample returns HTTP 503 for other outcomes that withhold the result. To confirm the session in the portal, open the application’s Sessions tab.
For a hosted organization, the SDK defaults to https://ingest.veriproof.app. Set VERIPROOF_ENDPOINT to the ingest endpoint shown in Set up SDK if it differs. When your test ingest service runs on your workstation over HTTP, also set VERIPROOF_DEMO_ALLOW_LOOPBACK=1 for this example.
Govern individual model and tool calls
Stop the first server and use a separate virtual environment for the LangGraph adapter 1.1.1. It requires Core 1.1.1 and LangGraph 1.2.11. In the new environment, use the same feed and wheels variables or set them again.
python -m pip download --no-deps --only-binary=:all: \
--index-url "$feed" --dest "$wheels" \
veriproof-sdk==1.1.1 veriproof-sdk-adapter-langgraph==1.1.1
python -m pip install "$wheels/veriproof_sdk-1.1.1-py3-none-any.whl" \
"$wheels/veriproof_sdk_adapter_langgraph-1.1.1-py3-none-any.whl" \
fastapi==0.165.0 uvicorn==0.55.0 langchain==1.4.5 langgraph==1.2.11
VERIPROOF_DEMO_MODE=adapter python -m uvicorn fastapi_langgraph_agent:app --host 127.0.0.1 --port 8000Run the same request. The SDK records two langgraph.model.call sessions and one langgraph.tool.lookup_shipment session on a successful run. Run veriproof --json sessions list --application-id "$APP_ID" and match sessionContext.externalReference to reference in the response. Use the session IDs from that list to inspect individual calls. An input-stage rule on langgraph.tool.lookup_shipment can stop the lookup before the tool runs.
The example sets GovernOptions.model for the scripted model so VeriProof can identify the model and provider on each model call. For your own model, supply its actual ID and provider if the integration does not report them. Check Required fields under Set up SDK after sending a session.
Report token usage
Declare the model call with execution_descriptor, then report the counts the provider returned from inside the action. VeriProof prices the call from those counts and the call’s model.
from veriproof_sdk import GovernedActionContext, GovernedExecutionDescriptor, GovernModel
async def reply(context: GovernedActionContext) -> dict:
response = await provider.complete(context.input)
context.report_token_usage(
input_tokens=response.usage.input_tokens,
output_tokens=response.usage.output_tokens,
)
return {"text": response.text}
result = await vp.govern(
"support.reply",
request,
reply,
model=GovernModel(id="gpt-4.1-mini", provider="openai"),
execution_descriptor=GovernedExecutionDescriptor.model_invocation("chat"),
)The counts are metadata, so VeriProof records them even when content capture is off. The last report wins. VeriProof records the model call when the action returns, so a call that raises has no counts. report_token_usage raises ValueError and records nothing for a count that isn’t an integer from 0 to 2147483647 (a bool doesn’t count), or when the call declared no model invocation. try_report_token_usage takes the same arguments and returns False instead of raising. A review checkpoint keeps the declaration for resume.
Handle a stop
Pass the governed action context into child work. Call context.throw_if_stopped() immediately before each protected side effect.
A live Stop directive applies only to its matching run or application. The SDK signals the action before it acknowledges the directive. It does not terminate the Python process. Reconcile the side effect when the result reports uncertain completion.
Add industry values
Generated values add the canonical policy field and evidence attribute with one .fact() call. Use facts for application-specific rule data.
from veriproof_sdk.verticals.insurance import PolicyLifecycleStatus
industry = PolicyLifecycleStatus.in_force.fact()The active field contract checks required fields, types, and allowed values before protected work begins.
Derive facts once
When every call carries the same kind of facts, register a fact extractor on the client instead of building facts at each call site. It receives the action name, input, session and invocation IDs, the adapter name, the tool name when an adapter governs a tool call, and any run_metadata you pass:
from veriproof_sdk import FactExtractionContext, Veriproof
def facts_from_call(context: FactExtractionContext):
if context.tool_name == "send_payment":
return {"payment_amount": context.input["amount"]}
return None
vp = Veriproof.from_env(fact_extractor=facts_from_call)Facts you pass to govern(facts=...) win over extracted facts with the same name. Extracted facts go through the same sanitization and field-contract checks as facts you pass yourself, and they’re saved in review checkpoints. A resumed review uses those saved facts without calling the extractor again.
If the extractor raises or returns something other than a JSON object, the call ends with failed and reason code fact_extraction_failed. The action doesn’t run. run_metadata only reaches the extractor; the SDK never sends it to VeriProof.
Add human review
When a rule sends an action for review, pass review=GovernReviewOptions(...) so VeriProof can build the reviewer’s request. Before your first review, check that:
- an active review profile exists in the portal, and you pass its key as
GovernReviewOptions(profile=...); - human review is turned on for your organization in Settings > Human review and escalation;
- an Administrator has granted the API key Human review access on the application’s Config > Keys tab; and
- the application has a public HTTPS callback URL registered. VeriProof doesn’t deliver outcomes to private or local addresses.
from veriproof_sdk import GovernReviewOptions
# Inside main(), in place of the earlier govern call:
result = await vp.govern(
"claims.pay",
claim,
pay_claim,
facts={"claim_amount": claim["amount"]},
review=GovernReviewOptions(
profile="claims-review",
proposed_action_summary="Review the proposed claim payment.",
),
)A missing profile fails with review_profile_not_found. A key without human review access fails with permission_denied. Neither runs the action.
Continue after human review
Save every review_required checkpoint in a protected workflow store. Verify signed callback bytes before parsing the response. A worker can then call the review runtime with the saved checkpoint and a rebuilt protected callback.
The runtime checks each callback against the signing keys VeriProof publishes at your endpoint. If your host can’t reach VeriProof, pass webhook_keys=PinnedWebhookKeySet(key_set_json) to reviews(). To check review event webhooks, use verify_webhook with the key set, your whsec_ subscription secret, or both.
Core Human Review uses a 12-field bounded brief and a response and resume-mode matrix. route_to_revision starts application-owned revision work and never runs the superseded payload. Private-note content remains in VeriProof and is excluded from the callback.
Use reviews.reconcile(...) after checking an uncertain durable effect. External systems do not provide a general exactly-once guarantee.
The hosted Server Ingest path is the default. Set the Edge endpoint option to use the Edge API of your VeriProof Agent Gateway.
See Core Human Review for the lifecycle contract and the runnable Python receiver guide for callback hosting.
Framework adapters
Choose an Enforce adapter for the operation you want to govern. Checks names the operation the adapter controls. Put the core SDK’s governed action around anything under Not covered.
| Framework | Package | Checks | Not covered |
|---|---|---|---|
| Anthropic SDK | veriproof-sdk-adapter-anthropic | One async Messages request | Sync clients, incremental streaming, and provider-hosted tools. |
| CrewAI | veriproof-sdk-adapter-crewai | Complete crew kickoff and selected tool calls | Independent model or task decisions inside the crew, synchronous kickoff and kickoff_for_each, and direct framework calls. |
| Google ADK | veriproof-sdk-adapter-google-adk | Complete buffered ADK event run and selected tool calls through the tool plugin | Provider-hosted tools, unselected tools, opaque custom tool loops, and direct framework calls. |
| LangGraph | veriproof-sdk-adapter-langgraph | Complete graph ainvoke, opt-in async ToolNode tool calls, and LangChain agent model calls through awrap_model_call | Per-node policy, streaming, synchronous ToolNode execution, and direct graph calls. |
| LlamaIndex | veriproof-sdk-adapter-llamaindex | Owned workflow runs, query-engine aquery, and selected or wrapped local tool calls | Local tools left out of the tools selection, tools an agent picks through a tool_retriever, unwrapped tools inside a query, streaming, and direct query-engine calls. |
| Microsoft Agent Framework | veriproof-sdk-adapter-agent-framework | Model calls, local tool calls, and streamed output | Provider-hosted tools and framework handoffs that bypass the middleware bundle are not covered. |
| OpenAI Agents | veriproof-sdk-adapter-openai-agents | Complete async agent run and opt-in local function tool calls | Incremental streaming, provider-hosted tools, tools of handoff agents not passed through govern_tools, and direct framework calls. |
| Pydantic AI | veriproof-sdk-adapter-pydantic-ai | Complete async agent run and selected function tool calls | Incremental streaming, unselected and MCP tools, provider-hosted tools, and direct framework calls. |
See the package catalog and Python release notes.