C-001 임상 검토 게이트 보강

This commit is contained in:
Yun Chan 2026-08-28 19:04:17 +09:00
parent 391fb9f4d0
commit 6988280b30
18 changed files with 1896 additions and 67 deletions

View file

@ -23,8 +23,9 @@ from difflib import SequenceMatcher
from enum import Enum
from typing import Iterable, Protocol
from .state_machine import IDEATION_STAGE_CAP, clamp_ideation_stage
# ── 출력 가드레일 상한 (R5) ──────────────────────────────
IDEATION_STAGE_CAP = 3 # 내담자 발화/상태가 넘을 수 없는 자살사고 단계 상한
CRISIS_HOTLINE_NUMBER = "109"
CRISIS_HOTLINE_LABEL = "자살예방상담전화 109"
CRISIS_RESOURCE_MESSAGE = (
@ -648,8 +649,8 @@ def sanitize_client_reply(
"""내담자 AI 응답 출력 가드레일.
1. 자살/자해 수단·방법 정보가 있으면 needs_regeneration=True(차단, 재생성 신호).
2. ideation_stage > IDEATION_STAGE_CAP(3) 이면 안전 상한 위반으로 기록(상태머신이 상한 강제하나
이중방어). 응답 자체 텍스트는 정서 표현이면 유지.
2. ideation_stage > IDEATION_STAGE_CAP(3) 이면 상태머신 계약 위반으로 차단하고
needs_regeneration=True를 반환한다(영속 상태 상한에 대한 이중방어).
"""
reasons: list[str] = []
blocked = False
@ -678,6 +679,7 @@ def sanitize_client_reply(
if ideation_stage > IDEATION_STAGE_CAP:
reasons.append(f"ideation_over_cap:{ideation_stage}>{IDEATION_STAGE_CAP}")
blocked = True
needs_regen = True
return OutputGuardResult(
text=humanize_pii_placeholders(text),
@ -689,7 +691,7 @@ def sanitize_client_reply(
def clamp_ideation(stage: int) -> int:
"""ideation_stage 를 안전 상한(3)으로 클램프 (R5)."""
return max(1, min(IDEATION_STAGE_CAP, stage))
return clamp_ideation_stage(stage)
def crisis_resource() -> dict[str, str]: