Local-first SDK and CLI for RAG and agent reliability tracing, citation checks, and failure diagnosis.
Project description
ContextTrace
Debug RAG failures before users find them.
ContextTrace is a local-first Python SDK and CLI for evaluating existing RAG and AI agent systems. It records retrieved chunks, selected context, answer claims, citations, token usage, latency, and agent events, then writes local traces and HTML reports without requiring a hosted dashboard.
Install
pip install contexttrace
contexttrace --version
contexttrace init
Optional integrations:
pip install "contexttrace[langchain]"
pip install "contexttrace[llamaindex]"
pip install "contexttrace[fastapi]"
pip install "contexttrace[langgraph]"
pip install "contexttrace[otel]"
pip install "contexttrace[all]"
Quickstart
contexttrace init
contexttrace demo --dataset refund_policy
contexttrace report --last
contexttrace doctor
By default, traces are stored locally in:
.contexttrace/contexttrace.db
SDK Example
from contexttrace import ContextTrace
ct = ContextTrace(project="support-rag")
with ct.trace(query="What is the refund policy?") as trace:
chunks = retriever.search("What is the refund policy?")
trace.log_retrieval(chunks)
trace.log_context(chunks[:5])
answer = llm.generate("What is the refund policy?", chunks[:5])
trace.log_answer(answer, usage={"total_tokens": 1200})
trace.log_citations([
{"claim": "Refunds are available within 30 days.", "source_chunk_id": "chunk_12"}
])
result = trace.evaluate()
print(result["failure"]["failure_type"])
BYO RAG Endpoint
Evaluate a running local or hosted RAG API without adding SDK code:
contexttrace eval \
--dataset evals/questions.json \
--endpoint http://localhost:8000/query \
--method POST \
--input-key question \
--answer-path $.answer \
--contexts-path $.contexts \
--citations-path $.citations \
--fail-on "failure_rate>0.25"
What It Catches
retrieval_misscitation_mismatchunsupported_answercontradicted_answerconflicting_sourcesshould_have_abstained- agent failures such as
stale_memory_usedandtool_error
Privacy
Local mode is the default. ContextTrace makes no network calls unless you configure an LLM judge provider or evaluate a RAG endpoint you provide.
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file contexttrace-0.1.0.tar.gz.
File metadata
- Download URL: contexttrace-0.1.0.tar.gz
- Upload date:
- Size: 53.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28067b3c4319fd056c1253433e5d142b2ca0db15d318da679fd8dd462c7d0e68
|
|
| MD5 |
b6c8a3babe96de0f47dd00ee27729829
|
|
| BLAKE2b-256 |
79bd28cac9acfb848279c950e09f2687c4c168be9db8b72ae64b2593b909d4ca
|
File details
Details for the file contexttrace-0.1.0-py3-none-any.whl.
File metadata
- Download URL: contexttrace-0.1.0-py3-none-any.whl
- Upload date:
- Size: 65.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cda758c3fec98d806f0ca71c75741d21b7bfef21e92f97de565ccd19f62e2546
|
|
| MD5 |
c00ab38edc2df3b5e73d52e9f178457c
|
|
| BLAKE2b-256 |
2e7d585aea764d8c621718db1b1c66beeb1062234448d27b975f59d7e33b51c7
|