Lightweight Python SDK for capturing LLM inference, tool execution, and application logs with client-side PII redaction.
Project description
inferspect-sdk
Lightweight Python SDK for capturing LLM inference logs, tool executions, and application logs — with client-side PII redaction so sensitive data never leaves your process unredacted.
Auto-instruments raw OpenAI / Anthropic / Google Gemini clients, plus framework integrations for LangChain and LlamaIndex. Sync and async APIs. No telemetry vendor lock-in — point it at any HTTPS ingestion endpoint that accepts the wire format.
Install
# Core only (no framework deps pulled in)
pip install inferspect-sdk
# With your stack:
pip install "inferspect-sdk[openai]"
pip install "inferspect-sdk[anthropic]"
pip install "inferspect-sdk[google]"
pip install "inferspect-sdk[langchain]"
pip install "inferspect-sdk[llamaindex]"
# Everything
pip install "inferspect-sdk[all]"
Quickstart — raw OpenAI
import asyncio
from openai import AsyncOpenAI
from chatbot_sdk import InferenceLogger
from chatbot_sdk.integrations.openai import instrument
async def main():
client = AsyncOpenAI()
logger = InferenceLogger.from_env() # reads CHATBOT_SDK_URL + CHATBOT_SDK_KEY
instrument(client, logger=logger) # ← one-line monkey-patch; idempotent
async with logger:
resp = await client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Say hello"}],
)
print(resp.choices[0].message.content)
# Every call is auto-traced — no per-call wrapping.
asyncio.run(main())
Set two env vars before running:
export CHATBOT_SDK_URL=https://your-ingestion-host/v1/logs
export CHATBOT_SDK_KEY=your-sdk-api-key
Quickstart — LangChain
from chatbot_sdk import InferenceLogger
from chatbot_sdk.integrations.langchain import SDKCallback
logger = InferenceLogger.from_env()
await logger.start()
callback = SDKCallback(sdk=logger)
result = await agent.ainvoke(
{"messages": msgs},
config={"callbacks": [callback]}, # every LLM + tool call inside is auto-traced
)
Quickstart — sync (Flask / Django / notebooks)
from chatbot_sdk import SyncInferenceLogger
logger = SyncInferenceLogger.from_env()
with logger:
with logger.inference(provider="openai", model="gpt-4o-mini") as span:
resp = client.chat.completions.create(...)
span.set_response(resp)
What gets logged
Per inference: provider, model, prompt_tokens, completion_tokens, latency_ms, ttft_ms (streaming), status (ok/error/cancelled/timeout), finish_reason, tool_calls_summary, input_preview, output_preview, plus per-request conversation_id / session_id / user_id if set via logger.context(...).
Per tool call: tool_name, args_preview, result_preview, latency_ms, status + error fields, linked to parent inference via parent_inference_request_id.
PII redaction
Runs inside your process before any event leaves over the network. Default recognizers: email, phone (E.164 + NA), credit card (Luhn-validated), US SSN, IBAN, IPv4, AWS access keys. Configurable via InferenceLogger(pii_redact=True, pii_recognizers=[...]).
Zero third-party deps for redaction (pure regex). Server-side PII can run as defense-in-depth if your ingestion service supports it.
Provider matrix
| Library | Integration | Pattern |
|---|---|---|
openai (AsyncOpenAI) |
chatbot_sdk.integrations.openai.instrument(client, logger=...) |
monkey-patch |
anthropic (AsyncAnthropic) |
chatbot_sdk.integrations.anthropic.instrument(client, logger=...) |
monkey-patch |
google-genai (AsyncClient) |
chatbot_sdk.integrations.google.instrument(client, logger=...) |
monkey-patch |
langchain-core |
chatbot_sdk.integrations.langchain.SDKCallback(sdk=logger) |
callback handler |
llama-index-core |
chatbot_sdk.integrations.llamaindex.LlamaIndexCallback(logger) |
callback handler |
| Anything else | async with logger.inference(...) as span: |
manual context manager |
Per-request context
Use logger.context(...) to propagate per-request IDs through nested LLM/tool calls without threading them by hand:
async with logger.context(conversation_id=conv_id, user_id=user_id):
resp = await client.chat.completions.create(...) # auto-traced, IDs stamped on the log
Links
- Source: https://github.com/itsdun1/inferspect
- Issues: https://github.com/itsdun1/inferspect/issues
- License: MIT
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 inferspect_sdk-0.2.2.tar.gz.
File metadata
- Download URL: inferspect_sdk-0.2.2.tar.gz
- Upload date:
- Size: 35.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb9585d8e08192fb418e589d648b0f88e45c76230b864275a7baa0ac7e38b309
|
|
| MD5 |
ef49c840a7370ad86f378cb765952f6f
|
|
| BLAKE2b-256 |
c710f6b2192d90c01d5abaa1e393c800813735055d94372ea4958629db1e55b9
|
File details
Details for the file inferspect_sdk-0.2.2-py3-none-any.whl.
File metadata
- Download URL: inferspect_sdk-0.2.2-py3-none-any.whl
- Upload date:
- Size: 35.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b40709223a57237ca5e5535300c6eff724dd20013db949449551835c4f2e2f6
|
|
| MD5 |
3ed42207ee15c221a821566b5dda4cfd
|
|
| BLAKE2b-256 |
59440cee97592bc940ff72e464e7ae8b4fff51b9b854460b0533a50111cd9763
|