Guardrails 패턴
class LLMGuardrails {
async validate(output: string): Promise<ValidationResult> {
const checks = await Promise.all([
this.checkToxicity(output),
this.checkHallucination(output),
this.checkPII(output),
this.checkPromptInjection(output),
]);
return {
safe: checks.every(c => c.safe),
violations: checks.filter(c => !c.safe),
};
}
}프롬프트 인젝션 방어
// 사용자 입력과 시스템 프롬프트 분리
const messages = [
{ role: "system", content: systemPrompt },
{ role: "user", content: sanitize(userInput) },
];입력/출력 양쪽 모두에서 검증하는 것이 중요합니다.
댓글 0