TraceMind
Record Python function executions and compare behaviour between application versions.
TraceMind is a Python SDK that records the inputs, outputs, errors, duration and application version of the functions you decorate. Because every trace carries a version label, you can run two versions of your code against the same inputs and see which functions now behave differently. An optional local LLM (through Ollama) can explain the differences.
It is aimed at code where a small change can silently alter results, such as pricing, discounts, tax and billing rules.
Features
- One decorator,
@tracemind.track, for sync andasyncfunctions. - Records arguments, return value, exception details, UTC start time, duration and app version.
- Arguments are snapshotted before the call, so a function that mutates its inputs is still recorded correctly.
- Traces are immutable and JSON-safe (
Trace.to_dict()/Trace.from_dict()). - Bounded output: depth, collection size and string length are capped, cycles are cut, and
NaN,bytesand memory addresses are normalised. - Never raises into your code. Tracking failures are logged at debug level and your function's result or exception passes through unchanged.
- Optional explanations from a local Ollama model. Nothing leaves your machine.
- No dependencies. Python 3.10+.
Installation
pip install "tracemind-regression>=0.1.2"
The distribution is named tracemind-regression; the import name is tracemind.
Quick start
import tracemind
@tracemind.track
def final_price(price, discount_percent):
return price - price * discount_percent / 100
@tracemind.track
def divide(a, b):
return a / b
final_price(200, 10)
try:
divide(1, 0)
except ZeroDivisionError:
pass
for trace in tracemind.get_records():
print(trace.function_name, trace.status.value, trace.args, trace.return_value)
final_price success [200, 10] 180.0
divide error [1, 0] None
Each record is a Trace. trace.to_dict() returns plain data:
{
'id': 'f93833137ec7449fa9f89367e66d737a',
'schema_version': 1,
'function_name': 'final_price',
'function_module': '__main__',
'args': [200, 10],
'kwargs': {},
'return_value': 180.0,
'status': 'success',
'error_type': None,
'error_message': None,
'error_traceback': None,
'started_at': '2026-11-19T22:23:02.382133+00:00',
'duration_ms': 0.003,
'app_version': 'v1',
'metadata': {},
}
Usage
Labelling the application version
Set TRACEMIND_APP_VERSION before starting your application. Traces from runs with different labels can then be compared.
# macOS / Linux
TRACEMIND_APP_VERSION=v1 python app.py
# Windows PowerShell
$env:TRACEMIND_APP_VERSION = "v1"; python app.py
Without it, traces are labelled unknown.
Reading and clearing traces
tracemind.get_records() # list[Trace], a snapshot
tracemind.clear_records() # empty the in-memory store (useful between tests)
Comparing two versions
The SDK records traces; it does not include a comparison engine. examples/demo.py shows the workflow: run a workload under v1, save trace.to_dict() to disk, run it under v2, then match traces by function name and arguments and diff the results.
python examples/demo.py # with TRACEMIND_APP_VERSION=v1, then =v2
Explaining differences with a local LLM
tracemind.llm_client sends a list of differences to a local Ollama model and returns a plain language explanation.
from tracemind.llm_client import explain_changes, OllamaError
changes = [
"final_price[12.34, 15]: 10.49 -> 10.48",
"final_price[20, 150]: -10.0 -> ERROR ValueError: discount cannot be more than 100%",
]
try:
print(explain_changes(changes))
except OllamaError as error:
print(f"No explanation: {error}")
OllamaError is raised if Ollama is not running, the model is not installed, the request times out, or the reply is unusable. Treat the explanation as optional. The model only sees the lines you pass it, so use it to summarise a diff, not as the source of truth for what changed.
Requires a running Ollama server with a model pulled, for example ollama pull mistral.
Configuration
| Environment variable | Default | Purpose |
|---|---|---|
TRACEMIND_APP_VERSION |
unknown |
Version label stored on every trace |
TRACEMIND_LLM_MODEL |
mistral |
Ollama model used by explain_changes |
OLLAMA_HOST |
http://localhost:11434 |
Ollama server address |
The Trace record
| Field | Type | Description |
|---|---|---|
id |
str |
UUID4 hex, generated automatically |
schema_version |
int |
Format version of the record |
function_name |
str |
__qualname__ of the decorated function |
function_module |
str |
__module__ of the decorated function |
args / kwargs |
list / dict |
Arguments as they were before the call, JSON-safe |
return_value |
Any |
JSON-safe return value, None on error |
status |
Status |
Status.SUCCESS or Status.ERROR |
error_type / error_message / error_traceback |
str | None |
Set only when status is ERROR |
started_at |
datetime |
Timezone-aware, UTC |
duration_ms |
float |
Measured with time.perf_counter() |
app_version |
str |
Value of TRACEMIND_APP_VERSION |
metadata |
dict |
Free-form extra data |
Trace is a frozen dataclass and validates itself on creation: started_at must be timezone-aware, duration_ms cannot be negative, and success and error fields cannot be mixed.
How it works
@track -> tracker.py observes the call: inputs, output, timing, errors
-> serialize.py makes values JSON-safe and size-limited
-> models.py builds an immutable Trace
-> collector.py stores traces (thread-safe, in memory)
| Module | Responsibility |
|---|---|
tracker.py |
The @track decorator |
models.py |
Trace and Status |
serialize.py |
to_jsonable(): bounded, strict-JSON conversion |
collector.py |
Collector with an optional max_records cap |
llm_client.py |
Ollama client built on urllib |
Serialisation limits: depth 6, 50 items per collection, 1,000 characters per string, 8,000 characters per traceback.
Limitations
- Traces are stored in memory only and are lost when the process exits. Persist them with
to_dict()if you need them across runs. - Arguments and return values are recorded as they are. There is no built-in redaction, so do not decorate functions that handle secrets or personal data.
- Only
Exceptionis recorded.BaseExceptionsubclasses such asasyncio.CancelledErrorare not. - For methods,
selfis recorded asargs[0]and serialised like any other object.
Development
git clone https://github.com/TejasDharmale/TraceMind.git
cd TraceMind
python -m venv .venv
# activate the environment, then:
pip install -e .
pip install pytest
python -m pytest
Contributions are welcome. Please open an issue before starting larger changes.
License
Metadata
Release files for tracemind-regression 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tracemind_regression-0.1.3.tar.gz | 15.8 kB | Without provenance | Details for tracemind_regression-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tracemind_regression-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for tracemind_regression-0.1.3-py3-none-any.whl |
Total release size: 28.9 kB
Release files / tracemind_regression-0.1.3.tar.gz
| Download URL | tracemind_regression-0.1.3.tar.gz |
|---|---|
| Size | 15.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
572eaff6fcd8ac3c66ba9d32a14e3da4381675a28f50e0a165305ac87b56a42d
|
|
BLAKE2b-256 checksum How to use checksums |
62bb9d7f36d778577f5fbd959c87586d9847fd911fbf2d2d3d480a98e8fb2d8d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / tracemind_regression-0.1.3-py3-none-any.whl
| Download URL | tracemind_regression-0.1.3-py3-none-any.whl |
|---|---|
| Size | 13.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9c36fdec9da7225c9585bb787b892b96889a5f9f5f85f78abf55f075b4b1d1fc
|
|
BLAKE2b-256 checksum How to use checksums |
5ed72e65b844380b2df98c814e64b4f5e794a83f9f8d530fd41f891648d011d1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for tracemind-regression 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.