"""投顾 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