Skip to main content

truthlock-io

Python client and command line tool for TruthLock: standing verification for AI responses.

pip install truthlock-io

The package is truthlock-io and the module is truthlock_io. The similarly named truthlock on PyPI belongs to a different company and does not talk to this service.

Verify a response

from truthlock_io import TruthLock

tl = TruthLock(api_key="tl_...", organization="field-service")

record = tl.verify_and_wait(
    question="How do I clear fault E-41 on the press?",
    response=answer_text,
)

if tl.may(record, "display"):
    show(answer_text)
elif tl.may(record, "display_with_caveat"):
    show(answer_text, caveats=record.caveats())
else:
    hold(record.review_ids())

The key and organization may also come from TRUTHLOCK_API_KEY and TRUTHLOCK_ORGANIZATION. TRUTHLOCK_URL points the client at a dedicated stack; the default is https://app.truthlock.io.

Verification takes seconds to a minute or two, so it is asynchronous. verify returns an id at once. wait polls with a growing interval and raises VerificationTimeout if it gives up; the verification carries on, and get finds it later.

Call What it does
verify(response, question=, external_id=, operation=, webhook_url=, meta=) Submit. Returns Accepted(id, status, status_url).
get(id) / wait(id) / verify_and_wait(...) / recent(limit) The Record: .grade, .claims, .caveats(), .review_ids(), .raw.
check(record, operation) The reliance Decision: allow, review or deny, per claim and overall.
may(record, operation) True only for allow.
respond(question, grounded=False) An answer from the organization's responder agent.
attestations(id) / export(id, path) Whether the record is attested and stands, with its signed chain; or the whole bundle as a zip.
webhook_deliveries(id) What was sent for the record, and what your receiver answered.

Errors are typed: AuthenticationError (401, 403), PaymentRequired (402: the plan's allowance is spent, or an invoice is past due), RateLimited (429, with .retry_after), NotFound, and ApiError for the rest.

Webhooks

Give an API key a webhook under Advanced → API keys → Webhook, or:

curl -X PUT https://app.truthlock.io/v1/api-keys/$KEY_ID/webhook \
  -H "X-API-Key: $ADMIN_KEY" -H "Content-Type: application/json" \
  -d '{"url": "https://example.com/hooks/truthlock"}'

The response carries the signing secret, whsec_..., once. When a verification submitted with that key finishes, TruthLock posts a verification.completed or verification.failed event, signed:

TruthLock-Signature: t=1700000000,v1=<hex HMAC-SHA256 of "<t>.<raw body>">

Verify against the raw bytes, before parsing them:

from truthlock_io import parse_webhook, WebhookSignatureError


@app.post("/hooks/truthlock")
async def hook(request):
    try:
        event = parse_webhook(
            await request.body(),
            request.headers.get("TruthLock-Signature"),
            WEBHOOK_SECRET,
        )
    except WebhookSignatureError:
        return Response(status_code=400)
    if event.completed:
        record = tl.get(event.verification_id)
    return Response(status_code=204)

parse_webhook rejects an altered body, another key's secret, and anything older than five minutes, which is what stops a captured delivery being replayed. Answer with any 2xx quickly and do the work afterwards: anything else is retried, eight times over about a day. A delivery may arrive more than once; event.id is the same each time.

Command line

$ export TRUTHLOCK_API_KEY=tl_...
$ truthlock verify --org field-service --file answer.txt --json | jq .overall.grade
"CONTRADICTED"
$ truthlock may 3f2a9b1c-... publish
review claims 1
$ truthlock attest 3f2a9b1c-... --export bundle.zip
Command
verify --file F | --text T [--question Q] [--no-wait] [--webhook-url U] Submit and wait. - reads standard input.
get ID, wait ID Fetch, or wait for, a record.
may ID OPERATION Prints the decision. Exit 0 only for allow.
attest ID [--export ZIP] The attestation chain, or the bundle.
respond QUESTION [--grounded] Ask the responder agent.
deliveries ID Webhook deliveries for a record.
webhook-verify --body F --signature H --secret S Check a captured delivery.

Every command takes --json. Exit codes: 0 done or allowed, 1 a finding that says no (failed run, decision other than allow, bad signature), 2 an error.

Metadata

Release files for truthlock-io 0.1.0

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

Source distribution (sdist)

Source distribution for truthlock-io 0.1.0
File Size Uploaded Provenance Actions
truthlock_io-0.1.0.tar.gz 53.7 kB Without provenance Details for truthlock_io-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for truthlock-io 0.1.0
File Interpreter ABI Platform Actions
truthlock_io-0.1.0-py3-none-any.whl Python 3 none any Details for truthlock_io-0.1.0-py3-none-any.whl

Total release size: 71.9 kB

Release files / truthlock_io-0.1.0.tar.gz

Download URL truthlock_io-0.1.0.tar.gz
Size 53.7 kB
Tags Source
SHA-256 checksum
How to use checksums
86150e88c47c003dd3ab6e72e8ea1cfa144d779c8c0bb7bc9e3ad271fcc09852
BLAKE2b-256 checksum
How to use checksums
dcf6e1e3d3c5473ea79ff0b75114c7d17be8f2fa01d1176aeec8035dd8360a75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / truthlock_io-0.1.0-py3-none-any.whl

Download URL truthlock_io-0.1.0-py3-none-any.whl
Size 18.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
54b3e9706ee33791d30c825e07f97fd0608cf99e6b6ca64f5813b51ff5284cb2
BLAKE2b-256 checksum
How to use checksums
35a90ecf0ce0ccf24c0921c7b4d9b8a469cd969473959d366e4cbb81cce7bea7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for truthlock-io 0.1.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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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