Skip to content

t7 explanation: evidence assembly + one anthropic call behind a strict-json seam - #2

Merged
vlobus merged 2 commits into
mainfrom
t7-explanation
Jul 9, 2026
Merged

vlobus merged 2 commits into
mainfrom
t7-explanation

Conversation

@vlobus

@vlobus vlobus commented Jul 8, 2026

Copy link
Copy Markdown
Owner

what

  • domain/explanation.py — the trust design: candidates (anomaly + recent news, each sentiment-scored) are built deterministically from stored data and numbered; the LLM returns prose reasoning plus the indices it cites, so it can never mint evidence. ExplainerLLM Protocol is the seam; AnthropicExplainer is the one concrete (SDK import deferred to construction, like FinBERT's torch). Strict pydantic validation of the reply (extra="forbid", index range check, duplicate indices deduped); anything else raises MalformedReply and stores nothing.
  • ingest/explain.pyexplain_anomaly orchestrator: idempotency check first (an explained anomaly costs no second LLM call), news window [bar_ts - 3d, bar close) so later news can't "explain" an earlier move, sequential to_thread sentiment scoring, one LLM call, commit as one unit of work.
  • store/repositories.pyExplanationRepository (natural-key upsert, on_conflict_do_nothing), NewsRepository.recent_for_symbol with a bounded window.
  • config: anthropic_api_key / anthropic_model required, no defaults; .env.example updated.

tests

  • LLM mocked everywhere; nothing can hit the live API (no test constructs AnthropicExplainer).
  • acceptance proven in integration: mocked LLM → stored Explanation linked to its anomaly by natural key with ≥ 1 EvidenceRef (the anomaly cites itself, so the floor holds even with zero news).
  • look-ahead guard: an after-the-fact article seeded past bar close never becomes a candidate.
  • idempotency saves the call, malformed reply stores nothing, unknown anomaly raises.
  • subagent code review done; the one must-fix (unbounded news window) fixed in the second commit.
  • full gate green: ruff, mypy strict, import-linter, pytest (85 passed).

vlobus added 2 commits July 5, 2026 22:48
…dapter, explain_anomaly orchestrator + explanation repository
…ahead), dedupe evidence indices, drop unused param
@vlobus
vlobus merged commit f83be9b into main Jul 9, 2026
1 check passed
@vlobus
vlobus deleted the t7-explanation branch July 9, 2026 20:00
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.

1 participant