Skip to main content

TraceroAI Python SDK

Send RAG traces to TraceroAI — a RAG observability and evaluation platform. Instrument any RAG pipeline (LangChain, LlamaIndex, or your own) and every answer becomes a debuggable trace.

Install

pip install traceroai

Usage

Context manager (recommended)

Times the block and sends the trace automatically:

from traceroai import TraceroClient

client = TraceroClient(
    base_url="https://traceroai.onrender.com",
    api_key="your_project_key",
)

with client.trace("How long does a refund take?") as t:
    t.log_retrieval(chunks, strategy="hybrid", config={"final_top_k": 3})
    t.log_prompt(prompt_text, version="grounded_v1")
    t.log_generation(
        answer,
        model="gpt-4o-mini",
        temperature=0,
        parameters={"top_p": 1, "max_tokens": 512},   # any tunable knobs
        prompt_tokens=1200, completion_tokens=80,      # -> server computes cost
    )

print(t.trace_id)

Read a trace back (server-computed diagnosis + evaluations):

trace = client.get_trace(t.trace_id)
trace["diagnosis"]["label"]      # e.g. "healthy_answer"
trace["generation"]["usage"]     # tokens + cost_usd

Decorator

For a function that returns (answer, chunks):

@client.traced(model="gpt-4o-mini", strategy="hybrid")
def answer(query: str):
    chunks = retrieve(query)
    return generate(query, chunks), chunks

answer("What is the maximum file upload size?")  # traced automatically

Low-level

client.log_trace(
    query={"original": question},
    retrieval={"strategy": "hybrid", "chunks": chunks},
    generation={"model": "gpt-4o-mini", "answer": answer},
)

Authentication (multi-tenant)

Pass your project API key; the server attributes traces to your project:

client = TraceroClient(base_url="https://traceroai.onrender.com", api_key="your_project_key")

Self-healing recovery (optional)

pip install "traceroai[recovery]"

RecoveryAgent (built on LangGraph) retries the RAG stage that TraceroAI diagnoses as broken — re-retrieving on a retrieval miss, re-generating with a stricter prompt on an unsupported claim — until the answer is healthy or it escalates to review. You supply your own retrieve/generate; every attempt is traced.

from traceroai.recovery import RecoveryAgent

agent = RecoveryAgent(client, retrieve=my_retrieve, generate=my_generate, max_attempts=3)
result = agent.run("How long does a refund take?")
# result["answer"], result["diagnosis"], result["attempts"], result["trace_ids"]

Experiment evaluation

A/B-test pipeline configs against a labeled dataset. Bring your own retrieve/generate and cases; each answer is graded by TraceroAI's server-side judge, the best variant is recommended, and the run shows up on your dashboard.

from traceroai.eval import run_experiment, Case, Variant

run_experiment(
    client=client,
    dataset=[Case("c1", "How long does a refund take?", "5-7 business days.")],
    retrieve=my_retrieve,   # (query, top_k) -> list[chunk dict]
    generate=my_generate,   # (query, context) -> answer str
    variants=[Variant("k3", "top_k=3", top_k=3), Variant("k5", "top_k=5", top_k=5)],
    project_id="my-app",
)

Telemetry is best-effort

If the API is unreachable, the SDK warns and continues — it never breaks your app or masks your own exceptions. Evaluations, diagnosis, and cost are computed server-side (the server is the source of truth).

Download files

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

Source Distribution

traceroai-0.3.2.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

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

traceroai-0.3.2-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file traceroai-0.3.2.tar.gz.

File metadata

  • Download URL: traceroai-0.3.2.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for traceroai-0.3.2.tar.gz
Algorithm Hash digest
SHA256 baca2f1fe91df996dfaab058c1941f9521e2fbcea763f50aa1226a2a70300f22
MD5 12289954721d1725e962f8123c453194
BLAKE2b-256 18a3da1966d9fc5b09259d61e7de3d5894cee3f14be5e3f4304adf9e510e276c

See more details on using hashes here.

File details

Details for the file traceroai-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: traceroai-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for traceroai-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 023b069129347a8c4a8aab8e2b465726ccffab346c2f274e7cb7e98b41c60ff2
MD5 ae4c256afe3d30ca85ff4d6f2544e2ae
BLAKE2b-256 800c6a6d9ccf13b97d6c4e1f8c7f50ed4bedb69da21f5a331042dab984003402

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 Sentry Error logging StatusPage Status page