Skip to main content

HILT: Human-IA Log Trace - Privacy-first logging format for AI interactions

Project description

HILT – Human–AI Log Tracing

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

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

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

hilt_python-0.2.5.tar.gz (23.6 kB view details)

Uploaded Source

Built Distribution

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

hilt_python-0.2.5-py3-none-any.whl (29.4 kB view details)

Uploaded Python 3

File details

Details for the file hilt_python-0.2.5.tar.gz.

File metadata

  • Download URL: hilt_python-0.2.5.tar.gz
  • Upload date:
  • Size: 23.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for hilt_python-0.2.5.tar.gz
Algorithm Hash digest
SHA256 685298ca799b1b8482a3eb119ee14538232946d9ca9140023f6e486d8116f627
MD5 e24360fe024e848648b1518ed3fe7b2d
BLAKE2b-256 cdf431c4032742f1d46c446fb5cbe95727ba7f0056bdf41bd603fee24bf31846

See more details on using hashes here.

File details

Details for the file hilt_python-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: hilt_python-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 29.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for hilt_python-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 be9e4b25e26f9aa9e5731c8e0ed1462797f207434b402602f205e5fdfa658736
MD5 9ab3196808c0a637d7a3cb1b72c25faf
BLAKE2b-256 69ac55070441a996f3e69555a897c95e0d8a9bd17830591edabe1a4428d74689

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