Point-in-time correct LLM instrumentation: tracing, version pinning, and look-ahead-bias protection for research pipelines
Project description
traceguard
Point-in-time correct LLM instrumentation — tracing, version pinning, and look-ahead-bias protection for research pipelines.
When you run LLMs over historical data — backtesting a signal, replaying a pipeline, re-scoring an archive — TraceGuard makes it structurally hard to accidentally use a model or prompt that did not yet exist at the point in time you are simulating.
traceguard.registry.models— model registry withreleased_at/available_to_us_at;select_model(..., strict=...)with mandatory explicit mode (no default), so anachronistic choices fail loudly.traceguard.registry.prompts— git-tracked YAML prompt templates;load_promptpins the content hash into every trace.traceguard.sdk.tracer—@tracedecorator andspan()context manager recording input hash, model/prompt versions, output, and perf into SQLAlchemy (SQLite by default).traceguard.sdk.normalizer— the single canonicalnormalize_input/input_hash(sorted keys, fixed float precision, normalized whitespace).traceguard.sdk.wrappers.anthropic—wrap_anthropicauto-instruments an Anthropic SDK client (extra:traceguard[anthropic]).traceguard.validators.lookahead— pure-function invariant validators (validate_feature_as_of,validate_model_timing,validate_reference_timing) that raiseInvariantViolation; call them in pytest/CI.
Install
[project]
dependencies = [
"traceguard @ git+https://github.com/lizhuojunx86/traceguard.git@v0.2.0-phase0#subdirectory=packages/traceguard",
]
Requires Python 3.11+.
Example
from datetime import datetime, timezone
from traceguard.registry.models import register_model, select_model
from traceguard.store.models import make_engine
engine = make_engine("sqlite:///traceguard.db")
register_model("demo-llm-2024", model_family="internal-ml",
capability_class="general-llm",
released_at=datetime(2024, 1, 10, tzinfo=timezone.utc),
available_to_us_at=datetime(2024, 2, 1, tzinfo=timezone.utc),
engine=engine)
# Backtesting as of mid-2025: models that arrived later are invisible.
model_id = select_model("general-llm",
available_at=datetime(2025, 6, 30, tzinfo=timezone.utc),
strict=True, engine=engine)
A complete runnable tour (synthetic data, no API keys) lives in examples/quickstart.
Contract
The binding interface contract — table schemas, SDK signatures, the four look-ahead invariants, SemVer rules — is in docs/SPEC.md.
Phase 0 scope: tracer, model/prompt registries, normalizer, invariants 1–3, Anthropic wrapper. Not yet: drift checks, replay sets (invariant 4), CLI, Postgres/TimescaleDB, OpenAI/Voyage wrappers — see TRACEGUARD_ROADMAP.md.
Development
cd packages/traceguard
uv sync
uv run pytest # 44 tests
License
Apache-2.0.
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 traceguard-0.2.0.tar.gz.
File metadata
- Download URL: traceguard-0.2.0.tar.gz
- Upload date:
- Size: 59.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d91e8ad21956524c5097a7e0345e9657d1ccef496fddec50eb383d51a61101fc
|
|
| MD5 |
34e0c9efc96d6a211040bc7966c54df7
|
|
| BLAKE2b-256 |
b7b851190a63ca599aef8b702db40f09c44d374f8a5630d080681eb3728f0c87
|
File details
Details for the file traceguard-0.2.0-py3-none-any.whl.
File metadata
- Download URL: traceguard-0.2.0-py3-none-any.whl
- Upload date:
- Size: 21.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ec265b29ebc90299134b508e6714b4ccbbfd8caa8a1bd1f30fd17d94df04e3f
|
|
| MD5 |
ce9837c0f520a8c1076b9cb94e6a5d8a
|
|
| BLAKE2b-256 |
569a2d8a2d5312a2b6e33628ef2f8d8f83fc281e18305819e7f9e18850c318ad
|