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.0.tar.gz (21.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.0-py3-none-any.whl (26.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hilt_python-0.2.0.tar.gz
  • Upload date:
  • Size: 21.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.0.tar.gz
Algorithm Hash digest
SHA256 11096de3a4310a2284781a36f28f0440c75e6d9afd51f347106341e1d6740770
MD5 33e70b59df377fb65ccf8338ee2fa317
BLAKE2b-256 8b6bbf845abd40024044e19604f0cffb98e6733cde8ca246c8193d71311cbdae

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hilt_python-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 26.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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4d2b8de0bbca65563df5ff030212a0df6f222404c3cb53adc5c1d341c1719164
MD5 e45490dd08b7c862d68d2e73e6da9edb
BLAKE2b-256 8ec7d27a9a21799618ca75f61ec18a8a41f07b88741c97bfd68c450b57200846

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