Skip to main content

LangChain integration for TruthVouch Trust API — hallucination detection and content verification

Project description

langchain-truthvouch

LangChain integration for the TruthVouch Trust API. Add hallucination detection and content verification to any LangChain pipeline in minutes.

Installation

pip install langchain-truthvouch

Quickstart

import os
os.environ["TRUTHVOUCH_API_KEY"] = "your-api-key"

from truthvouch_langchain import TruthVouchGuard

guard = TruthVouchGuard(threshold=0.8)
result = guard("The Eiffel Tower is located in Berlin.")
print(result.passed)        # False — low trust score
print(result.trust_score)   # e.g. 0.21
print(result.claims)        # list of per-claim verification results

Components

TrustApiClient

Low-level async/sync client for the Trust API verify endpoint.

from truthvouch_langchain import TrustApiClient

client = TrustApiClient(
    api_key="your-api-key",           # or set TRUTHVOUCH_API_KEY env var
    base_url="http://localhost:5004/api/v1/trust",  # default
)

result = client.verify_sync("Paris is the capital of France.", mode="standard")
print(result.trust_score)  # 0.97

TruthVouchRetriever

Wraps any document list with trust verification. Documents below the threshold are filtered out.

from langchain_core.documents import Document
from truthvouch_langchain import TruthVouchRetriever

retriever = TruthVouchRetriever(
    api_key="your-api-key",
    threshold=0.75,
    mode="spot_check",
)
docs = retriever.get_relevant_documents("What is the capital of France?")
# Each doc has doc.metadata["trust_score"] set

TruthVouchCallbackHandler

Automatically verifies every LLM response via a LangChain callback.

from langchain_openai import ChatOpenAI
from truthvouch_langchain import TruthVouchCallbackHandler

handler = TruthVouchCallbackHandler(
    api_key="your-api-key",
    threshold=0.8,
    raise_on_low_trust=False,  # set True to raise TrustThresholdError
)

llm = ChatOpenAI(callbacks=[handler])
response = llm.invoke("Tell me about the Eiffel Tower.")

TruthVouchGuard

Simple callable guard — verify any text before displaying or acting on it.

from truthvouch_langchain import TruthVouchGuard

guard = TruthVouchGuard(threshold=0.8)
result = guard("Some text to verify")
if not result.passed:
    print("Low trust score:", result.trust_score)

Configuration

Parameter Env var Default
api_key TRUTHVOUCH_API_KEY (required)
base_url http://localhost:5004/api/v1/trust
threshold 0.8
mode spot_check

License

Apache-2.0

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

langchain_truthvouch-1.0.0.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

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

langchain_truthvouch-1.0.0-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file langchain_truthvouch-1.0.0.tar.gz.

File metadata

  • Download URL: langchain_truthvouch-1.0.0.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for langchain_truthvouch-1.0.0.tar.gz
Algorithm Hash digest
SHA256 76afdd9c1c4f6c3d08e2f2c5ff0b894de082ea98c41bb6fa5ec16f5b1ab46864
MD5 756bb0a82eb544840f8328281dfd57bf
BLAKE2b-256 1d0248da95fc17717e99c11cecb532dfabf82dc31b57e0d1b00862b3f2e08af6

See more details on using hashes here.

File details

Details for the file langchain_truthvouch-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_truthvouch-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 812163f0ddcc956683fd55b4c928e7234333e40314eb64f27a937f421bd7a14a
MD5 58db546a79de85b5210cdbbc38e98dda
BLAKE2b-256 aa86a234edad34f3d13b879dbfd91307bf89fc9bb4f5463155795b97179dc2b4

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