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.

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.1.0.tar.gz (20.7 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.1.0-py3-none-any.whl (25.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hilt_python-0.1.0.tar.gz
  • Upload date:
  • Size: 20.7 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.1.0.tar.gz
Algorithm Hash digest
SHA256 56bc09338c2f233c97ce967c5a7e09a2f28bb3574fd6988117e57afbff384b31
MD5 5559b9e5dbaa6be4ce1fcbafc0990df2
BLAKE2b-256 b3faf420a16a1770e105b8e925b794a2ad676ba198e6cd7e2e16f3d54e631735

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hilt_python-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 25.7 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f3ecf5f2af317e76a3d33729269de25ec0c7eed709f7aa4e380263e04b6cefcf
MD5 367f9e7344faaf7cbb96bfee0844dfa6
BLAKE2b-256 bf8975dae13d142e6e4560f346550e145126af64b32583152d5cb4a321c5638b

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