feat(llm): foundational LLM infra package + §19 redaction (#960) #1168
No reviewers
Labels
No labels
admin
analytics
auth
automation
bug
business
chore
ci
compliance
data
data-moat
docs
duplicate
dx
enhancement
Fable 5 ревью
feedback/max
generative
GG-форсайт
needs-discussion
needs-human
observability
pause-bots
performance
priority/p0
priority/p1
priority/p2
priority/p3
scope/backend
scope/db
scope/devops
scope/frontend
scope/qa
scrapers
security
site-finder
stage/1
stage/2
status/blocked
status/done
status/needs-analysis
status/needs-fix
status/qa
status/ready
status/review
status/wip
tech-debt
tradein
ux
week ревью 1
wontfix
вторичка
ИРД
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: lekss361/gendesign#1168
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "feat/llm-infra-960"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Foundational LLM infrastructure (#960, ТЗ §12.4/§7.4) — new
backend/app/services/llm/package. No consumers yet (#956 граддок-extraction / #957 chat will consume it). Provider: external OpenAI (owner decision); architecture keeps the forecasting engine fully deterministic — LLM is an optional layer that always degrades to a deterministic fallback.Safety-by-default (the whole point of the gating)
llm_enabled=Falseby default +openai_api_key=None→complete()returns the fallback before constructing any provider / opening any socket. Prod cannot call OpenAI until deliberately enabled. (Proven by ahttpx.Clientinstantiation tripwire test.)SafePayloadcontract — callers physically cannot pass raw DB rows, only vetted fields/aggregates/public text;is_confidential=True→ hard block (RedactionRefusedError→ fallback, provider never called);scrub_safe_payload()runs unconditionally before any external call.Authorizationheader, never logged/echoed; no key literal anywhere (grep sk-empty).LLMResult(fallback_used=True)— never an unhandled exception. Bounded retry+backoff.Design
provider.py— abstractLLMProvider(withis_externalseam for a future RU-hosted GigaChat/YandexGPT provider, no caller changes) +OpenAIProvider(raw httpx, tool/function-calling pass-through).redaction.py— the §19 layer.client.py— enabled→redact→guardrails→provider→retry→fallback.prompts.py— minimal versioned templates. Config extended incore/config.py.openaiSDK →pyproject.toml/uv.lockuntouched (no deploy-abort risk).Test plan
uv run pytest tests/services/llm/ -q→ 47 passedruff check+mypy(strict) → cleanOPENAI_API_KEYin backend+worker runtime env (out of git) andLLM_ENABLED=trueafter the §19 sign-off + key rotation. Until then: dormant, zero network.Notes
Refs #960