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
Release files for langchain-truthvouch 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| langchain_truthvouch-1.0.0.tar.gz | 16.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| langchain_truthvouch-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 30.8 kB
Release files / langchain_truthvouch-1.0.0.tar.gz
| Download URL | langchain_truthvouch-1.0.0.tar.gz |
|---|---|
| Size | 16.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
76afdd9c1c4f6c3d08e2f2c5ff0b894de082ea98c41bb6fa5ec16f5b1ab46864
|
|
BLAKE2b-256 checksum How to use checksums |
1d0248da95fc17717e99c11cecb532dfabf82dc31b57e0d1b00862b3f2e08af6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / langchain_truthvouch-1.0.0-py3-none-any.whl
| Download URL | langchain_truthvouch-1.0.0-py3-none-any.whl |
|---|---|
| Size | 14.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
812163f0ddcc956683fd55b4c928e7234333e40314eb64f27a937f421bd7a14a
|
|
BLAKE2b-256 checksum How to use checksums |
aa86a234edad34f3d13b879dbfd91307bf89fc9bb4f5463155795b97179dc2b4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|