Files
Mutual_Fund/service/advisor_agent/compliance.py
T

17 lines
550 B
Python
Raw Normal View History

2026-09-13 16:19:24 +08:00
"""投顾 Agent 输出合规校验。"""
from __future__ import annotations
from common.common_const import ERR_CODE_LLM_ERROR
from utils.exceptions import ApiError
def find_sensitive_words(content: str, words: list[str]) -> list[str]:
return [word for word in dict.fromkeys(words) if word and word in content]
def ensure_safe_content(content: str, words: list[str]) -> bool:
matched = find_sensitive_words(content, words)
if matched:
raise ApiError(ERR_CODE_LLM_ERROR, "AI输出包含敏感或违规表述")
return True