İçeriğe geç

Guardrails: System Prompt, İçerik Filtreleri, Allow/Deny Listeleri

Pratik guardrail kütüphaneleri (Guardrails AI, NeMo, Llama Guard). Allow/deny listeleri, content moderation API'leri.

Şükrü Yusuf KAYA
10 dakikalık okuma
İleri

Guardrails: Pratik Araçlar

Açık kaynak, deklaratif:
from guardrails import Guard from guardrails.hub import ( DetectPII, ToxicLanguage, CompetitorCheck ) guard = Guard().use_many( DetectPII(pii_entities=["EMAIL", "PHONE"]), ToxicLanguage(threshold=0.8), CompetitorCheck(competitors=["X", "Y"]), ) result = guard(llm_call, prompt=user_input) if result.validation_passed: print(result.validated_output)

Allow/Deny List Pattern#

python
# Domain-spesifik whitelist
ALLOWED_TOPICS = ["product info", "order status", "refund policy"]
DENIED_TOPICS = ["legal advice", "medical advice", "competitor comparison"]
 
# LLM-judge ile sınıflandır
def is_topic_allowed(query: str) -> bool:
judge_prompt = f"""Kullanıcı sorgusunu sınıflandır:
ALLOWED: {ALLOWED_TOPICS}
DENIED: {DENIED_TOPICS}
 
Query: "{query}"
Tek kelime: ALLOWED veya DENIED."""
return judge_call(judge_prompt) == "ALLOWED"
Allow/deny list
Layered approach: Vendor moderation (cheap) → Custom guardrails (specific) → LLM judge (nuanced) → Audit log (post-hoc). Hiçbiri %100 değil ama 4'ü birlikte %99.9.

Yorumlar & Soru-Cevap

(0)
Yorum yazmak için giriş yap.
Yorumlar yükleniyor...

İlgili İçerikler