feat: add look-ahead causality auditor - #25
Merged
Conversation
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.
There was a problem hiding this comment.
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_causalplusCausalityReport,CausalityError, andLeakEvent(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.diagnosticversion to0.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)})" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
audit_lookaheadandassert_causalas public APIs for perturbation-based feature causality auditing.0.1.0b23for 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