Files
US2KR/us2kr/llm/base.py
T
jsahnandClaude Fable 5 ed48f4c96b Add an LLM fact-check pass over the generated briefing
After summarisation the report is verified against the collected
payload (numbers, directions, unsupported claims) by a second LLM call
with a Verification JSON schema. Major issues trigger one revision and
a re-check; minor-only verdicts are normalized to ok. Failures never
block delivery. The verdict is stored in the result JSON and shown on
the dashboard (badge + 검증 메모). Disable with US2KR_VERIFY_ENABLED.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-01 10:37:39 +09:00

28 lines
998 B
Python

"""LLM provider interface. Implementations must be side-effect free apart from the HTTP call."""
from __future__ import annotations
from typing import Protocol
from us2kr.models import MarketPayload, Report, Verification, VerificationIssue
class LLMError(RuntimeError):
"""Raised when every configured model failed to produce a valid Report."""
class LLMProvider(Protocol):
def summarize(self, payload: MarketPayload) -> tuple[Report, str]:
"""Return (validated Report, model id that produced it). Raise LLMError on total failure."""
...
def verify(self, payload: MarketPayload, report: Report) -> tuple[Verification, str]:
"""Fact-check `report` against the payload. Raise LLMError on total failure."""
...
def revise(
self, payload: MarketPayload, report: Report, issues: list[VerificationIssue]
) -> tuple[Report, str]:
"""Return a corrected Report addressing `issues`. Raise LLMError on total failure."""
...