Skip to main content

HILT – Human–AI Log Tracing

HILT logo

Build Status Coverage PyPI Python 3.10+ License

HILT is a privacy-first, open-source format for logging human–AI interactions. Drop in one line at startup and every LLM call is captured with prompts, completions, metrics, and error context—no refactors, no custom wrappers.

What’s inside today

  • One-line auto-instrumentation for the official OpenAI Python SDK (client.chat.completions.create)
  • Deterministic conversation threading with prompt/completion links and reply metadata
  • Rich telemetry: latency, token usage, cost estimates, HTTP-style status codes, and error surfaces
  • Storage backends you control: append-only JSONL files or real-time Google Sheets dashboards
  • Thread-safe context management so you can override sessions per request, per worker, or per tenant
  • Manual event logging via Session.append() for tool calls, human feedback, or guardrail results

Installation

pip install hilt

Need Google Sheets streaming? Install the Sheets extra:

pip install "hilt[sheets]"

Quick start

from hilt import instrument, uninstrument
from openai import OpenAI

# Enable automatic logging (writes to logs/chat.jsonl by default)
instrument(backend="local", filepath="logs/chat.jsonl")

client = OpenAI()
response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Give me three onboarding tips"}],
)

print(response.choices[0].message.content)

# Stop logging when your app shuts down
uninstrument()

After the single instrument() call:

  • Prompts and completions are recorded as separate events
  • Latency, tokens, cost, and status codes are populated automatically
  • Conversation IDs remain stable so you can trace every exchange end to end
  • Pick the columns you need for privacy or dashboards (see below)

Column selection

instrument(..., columns=[...]) works for both JSONL and Google Sheets backends. If you omit the argument, JSONL writes the full event payload while Sheets defaults to every column listed here.

Column Description
timestamp ISO timestamp of the event (UTC)
conversation_id Stable thread identifier (conv_xxx)
event_id Unique event UUID (useful for reply linking)
reply_to Event ID this message responds to
status_code HTTP-like status from providers (e.g., 200, 429)
session Human-readable session alias (first characters of the ID)
speaker human / agent plus identifier
action Event type (prompt, completion, system, …)
message Normalised single-line content (truncated to 500 chars)
tokens_in Prompt tokens (if provider reports usage)
tokens_out Completion tokens (if provider reports usage)
cost_usd Monetised cost for the call (six decimal precision)
latency_ms Wall-clock latency from request start to response
model Provider/model label returned by the SDK
relevance_score Generic score slot (e.g., retrieval relevance)
instrument(
    backend="local",
    filepath="logs/redacted.jsonl",
    columns=["timestamp", "speaker", "action", "tokens_out", "cost_usd"],
)

Storage options

Local JSONL (default)

instrument(backend="local", filepath="logs/app.jsonl")
  • Privacy-first: data never leaves your environment
  • Plays nicely with analytics tooling (Python, Pandas, Spark, etc.)

Google Sheets (real time)

See Google Sheets setup guide for credential and sheet ID steps.

instrument(
    backend="sheets",
    sheet_id="1abc...",
    credentials_path="credentials.json",
    worksheet_name="LLM Logs",
    columns=["timestamp", "message", "cost_usd", "status_code"],
)
  • Great for support, QA, or cost monitoring teams
  • Columns control both ordering and visibility
  • Works with credentials_path or in-memory credentials_json

Advanced usage

Provider selection

instrument(
    backend="local",
    filepath="logs/app.jsonl",
    providers=["openai"],  # Anthropic / Gemini planned
)

Passing an empty list opens the session without patching any providers—useful for manual logging scenarios.

Troubleshooting highlights

  • Nothing recorded? Ensure instrument() runs before importing the OpenAI client.
  • Async apps? Use the same call; the instrumentation is thread-safe and works with AsyncOpenAI.
  • Large logs? Rotate files daily (logs/app-YYYY-MM-DD.jsonl) and prune with a cron job.
  • Sheets failing? Double-check the service account has editor access and that hilt[sheets] is installed.

See docs/ for deeper guides on privacy, advanced contexts, and FAQ.

Development

Contributions are welcome! Start with CONTRIBUTING.md. The test suite lives in tests/, and linting/type checking is configured via Ruff, Black, and MyPy.

TODO

  • Add auto-instrumentation for Anthropic Claude
  • Add auto-instrumentation for Google Gemini
  • Add auto-instrumentation for LangGraph

License

Released under the Apache License 2.0.

Installation

pip install hilt-python

Release files for hilt-python 0.2.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hilt-python 0.2.8
File Size Uploaded
hilt_python-0.2.8.tar.gz 25.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hilt-python 0.2.8
File Interpreter ABI Platform
hilt_python-0.2.8-py3-none-any.whl Python 3 none any Details

Total release size: 57.4 kB

Release files / hilt_python-0.2.8.tar.gz

Download URL hilt_python-0.2.8.tar.gz
Size 25.9 kB
Tags Source
SHA-256 checksum
How to use checksums
288e9018107972e41ec3e25b9f5f337ae56399e267f65b3cf2a06f2e61f78924
BLAKE2b-256 checksum
How to use checksums
592ffcdf4898263538a187097191be1e40bb58e6e9c7b110c015129cdd9cfca7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.12.11 Linux/6.11.0-1018-azure

Release files / hilt_python-0.2.8-py3-none-any.whl

Download URL hilt_python-0.2.8-py3-none-any.whl
Size 31.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c7bff29c67b7e8e27529fded094573683e09d490324e11d63bccc3ecd9b15d07
BLAKE2b-256 checksum
How to use checksums
3951e247008e16b95a6490ed5e487ffe973a7ca8d9c947aea9d12ee0983db37f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.12.11 Linux/6.11.0-1018-azure

Release history Release notifications | RSS feed

This release

0.2.8 This release

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page