Skip to main content

Python SDK for sending RAG traces to TraceroAI

Project description

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")

print(t.trace_id)

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"]

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

traceroai-0.2.0.tar.gz (10.3 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.2.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for traceroai-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4291cedbf09d2857f384c93d54a904120b90cb13f63f7f2a68a1a24ccb601638
MD5 ef58f14b288b30c5a7cbbbf7d4868dfa
BLAKE2b-256 4bf240390870ee6c044324a986def861d1b3f75ef5f0c1f77e48294787ebd41f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: traceroai-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5412011fc32a50e09bd01a6affb02437ffa6394ee68e04d8ba77890a62ffb437
MD5 046f07be28b36e6b657de96e2f03d8da
BLAKE2b-256 06c9cc0a75bbae43c239d5629d20317640429690f9a76d2b7be42779cee535d7

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