Skip to content

feat: add look-ahead causality auditor - #25

Merged
stefan-jansen merged 8 commits into
mainfrom
feat/lookahead-causality-audit
Jul 20, 2026
Merged

feat: add look-ahead causality auditor#25
stefan-jansen merged 8 commits into
mainfrom
feat/lookahead-causality-audit

Conversation

@stefan-jansen

Copy link
Copy Markdown
Contributor

What

  • Add audit_lookahead and assert_causal as public APIs for perturbation-based feature causality auditing.
  • Detect future-data leakage by comparing baseline and corrupted feature outputs at configurable cutoffs.
  • Report effective probes, skipped probes, indeterminate coverage, and leaking columns.
  • Bump the package version to 0.1.0b23 for release after merge.

Why

Feature pipelines need an executable causality gate that catches look-ahead leakage before research results or models reach production. The audit distinguishes confirmed causal behavior from vacuous or under-covered runs instead of silently passing incomplete evidence.

Verification

  • Full suite: 5,285 passed, 21 skipped
  • Focused causality suite: 48 passed
  • API contract suite: 5 passed
  • Ruff, formatting, ty, and pre-commit: passed
  • Package build and isolated wheel smoke test: passed

Model-class-agnostic look-ahead gate for feature extractors based on
future-perturbation invariance: corrupt input rows after a cutoff, re-run
the extractor, and assert features at t <= cutoff are unchanged. A measured
per-column determinism noise floor separates real leaks from unseeded jitter.

- evaluation/causality.py: audit_lookahead, assert_causal, CausalityReport,
  CausalityError, LeakEvent; nan/shuffle/noise corruptions; auto cutoffs;
  reuses reporting/ renderers for to_html/to_json/to_markdown.
- Exported through api.py and the package __init__; registered in the public
  API contract.
- Synthetic Polars unit tests covering causal/leaky/nondeterministic cases,
  each corruption strategy, auto cutoffs, single-series keys, and rendering.
Copilot AI review requested due to automatic review settings July 20, 2026 16:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Introduces a new look-ahead / causality auditing capability to ml4t.diagnostic that can detect future-data leakage in feature extractors via perturbation-based invariance checks, and exposes it as public API (with rendering and CI-friendly assertions).

Changes:

  • Add audit_lookahead / assert_causal plus CausalityReport, CausalityError, and LeakEvent (new causality audit engine and reporting bridge).
  • Add a comprehensive synthetic test suite validating leak detection, determinism handling, cutoffs/corruptions, and reporting formats.
  • Export the new APIs through the public surface + update API contracts and bump ml4t.diagnostic version to 0.1.0b23.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/test_integration/test_backtest_result.py Import formatting/reordering to satisfy style/lint constraints.
tests/test_integration/test_backtest_profile.py Minor import/whitespace cleanup.
tests/test_evaluation/test_causality.py New end-to-end tests for look-ahead causality auditing behavior and rendering.
tests/contracts/public_api_contract.json Update public API contract to include new causality APIs/types.
tests/contracts/evaluation_api_surface.json Update evaluation API surface contract to include new causality APIs/types.
src/ml4t/diagnostic/integration/init.py Minor whitespace cleanup.
src/ml4t/diagnostic/evaluation/causality.py New causality auditor implementation (core logic, report schema bridge, corruption strategies).
src/ml4t/diagnostic/evaluation/AGENTS.md Document new causality auditor as a main evaluation entry point.
src/ml4t/diagnostic/evaluation/init.py Re-export causality APIs/types from the evaluation package.
src/ml4t/diagnostic/api.py Add causality APIs/types to the top-level public API module exports.
src/ml4t/diagnostic/init.py Version bump + re-export causality APIs/types at package top-level.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +145 to +148
def get_dataframe(self, name: str | None = None) -> pl.DataFrame:
if not self.leak_rows:
return pl.DataFrame()
return pl.DataFrame(self.leak_rows)
Comment on lines +780 to +788
if all(k in output.columns for k in keys):
return output
if len(output) == len(frame):
return output.with_columns([frame.get_column(k) for k in keys])
raise ValueError(
"extractor output does not contain key columns "
f"{list(keys)} and is not row-aligned with the input frame "
f"(output rows={len(output)}, input rows={len(frame)})"
)
@stefan-jansen
stefan-jansen merged commit cb9b124 into main Jul 20, 2026
11 checks passed
@stefan-jansen
stefan-jansen deleted the feat/lookahead-causality-audit branch July 20, 2026 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants