Skip to main content

Send an AI workflow's run evidence to Veracity for verification.

Project description

veracity-connect-python

veracity-connect sends an AI workflow's run evidence to Veracity for verification.

This is the standalone Python SDK package for Veracity Connect.

Install

After the package is published to PyPI:

pip install veracity-connect

For optional integrations:

pip install "veracity-connect[langchain]"
pip install "veracity-connect[otel]"

If you need the current unreleased main branch:

pip install "veracity-connect @ git+https://github.com/nardosstem/veracity-connect-python.git@main"

Quick Start

This is a reference example for a common SQL-backed workflow. The SDK is not limited to this shape: create a VeracityRun, attach the evidence your workflow used, record the tool calls your workflow executed, set the artifact your workflow produced, and send the run to Veracity.

from veracity_connect import NativeArtifactBuilder, VeracityClient, VeracityRun, query_ref

client = VeracityClient(
    base_url="https://app.veracity.example",
    pairing_token="vrc_...",
)

run = VeracityRun(
    agent_name="acme-finance-agent",
    framework="langgraph",
)
run.attach_source("financials.csv", alias="financials")
run.record_sql(
    "SELECT SUM(revenue) AS total_revenue FROM financials",
    output={"columns": ["total_revenue"], "rows": [[240000]]},
    alias="revenue_totals",
)
artifact = (
    NativeArtifactBuilder()
    .text("Total revenue was ")
    .ref(query_ref("revenue_totals", 0, "total_revenue"), "$240,000")
    .text(".")
    .build(source_aliases=run.source_aliases())
)
run.set_artifact(native=artifact)
receipt = client.send(run, prompt="Summarize revenue.")

You can also load connection settings from the environment:

export VERACITY_BASE_URL="https://app.veracity.example"
export VERACITY_PAIRING_TOKEN="vrc_..."
from veracity_connect import VeracityClient

client = VeracityClient.from_env()

What To Record

attach_source(...) accepts source files or inline content. CSV sources are sent as text; Excel, SQLite, and DuckDB files are sent as encoded file content.

record_sql(...) records SQL tool calls and their outputs for replay/verification. If your workflow is already instrumented, the optional OpenTelemetry and LangChain integrations can collect supported tool calls for you. record_tool_call(...) is generic and can carry non-SQL tool calls too; the connector preserves them in the envelope for provenance/native-hint context even when Veracity's replay path is currently SQL-authoritative.

set_artifact(...) records the final output Veracity should check, either as rendered text, an Excel workbook, or both.

Optional integrations:

  • veracity_connect.langchain.VeracityCallbackHandler preserves LangChain/LangGraph tool calls in the envelope and upgrades SQL query calls into replayable record_sql(...) entries when possible.
  • veracity_connect.otel.VeracitySpanProcessor does the same for OpenTelemetry execute_tool spans, while still treating backend replay as the authority on what becomes verified proof.

Native Citation Hints

When your workflow can expose its own evidence refs, emit them from the connector/workflow layer rather than teaching the agent to write Veracity-specific strings itself.

  • raw source reads: source.<source_alias>[row].<column>
  • derived outputs: rows.<output_alias>[row].<column>

The helper API keeps those refs stable:

from veracity_connect import NativeArtifactBuilder, output_ref, source_ref

builder = NativeArtifactBuilder()
builder.text("Q3 source revenue was ")
builder.ref(source_ref("financials", 0, "revenue"), "$120,000")
builder.text("; rounded output was ")
builder.ref(output_ref("python_postprocess", 0, "rounded_total"), "$120,000")
artifact = builder.build(source_aliases=run.source_aliases())
run.set_artifact(native=artifact)

These hints are additive only. Veracity still replays authoritative tool calls and treats imported native hints as evidence, not trust by themselves.

Example-Agent Pattern

Keep the agent logic framework-native and inject Veracity-specific aliases/citations in the wrapper that packages the run:

def invoke_agent(inputs) -> dict:
    return agent.invoke(inputs)


def build_veracity_run(agent_result: dict) -> VeracityRun:
    run = VeracityRun(agent_name="acme-finance-agent", framework="langgraph")
    run.attach_source("financials.csv", alias="financials")
    run.record_sql(agent_result["sql"], output=agent_result["rows"], alias="revenue_totals")
    run.set_artifact(native=build_native_artifact(run, agent_result))
    return run

For a fuller mixed SQL + non-SQL example, see examples/mixed_tool_workflow.py.

Envelope Contract

The SDK sends an Agent-Run Evidence Envelope to POST /workspace/api/agent-runs/ingest with the pairing token in the X-Veracity-Pairing-Token header. The token is never serialized into the JSON payload.

payload = run.to_dict()
payload_json = run.to_json()
restored = VeracityRun.from_dict(payload)

Supported source types are csv, excel, sqlite, and duckdb. JSON sources are rejected until backend replay support exists.

Development

python -m venv .venv
source .venv/bin/activate
python -m pip install -U pip
python -m pip install -e ".[dev]"
python -m pytest
python -m build
python -m twine check dist/*

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

veracity_connect-0.2.0.tar.gz (21.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

veracity_connect-0.2.0-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file veracity_connect-0.2.0.tar.gz.

File metadata

  • Download URL: veracity_connect-0.2.0.tar.gz
  • Upload date:
  • Size: 21.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for veracity_connect-0.2.0.tar.gz
Algorithm Hash digest
SHA256 249cc54463525f783df74da4a2d971cec37cac71a2f33d24e264018c558311ad
MD5 7c117bc406b53d277e7c08d19f0c5867
BLAKE2b-256 b883b9d6dd651ed344a96fd05bf99791c078026a2efc9a259f87c4a1f6b2c0bf

See more details on using hashes here.

File details

Details for the file veracity_connect-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for veracity_connect-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 49700b8f98206daff15ed06295f627955a1d1a4a89c3769e83b3ffb384bad1f9
MD5 66f230002bf6e69a8e86ba270d3ccb77
BLAKE2b-256 809cc5876d8b52c400d2064ef504088f78e2430d5ca6696228e344f067dc9fce

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page