मुख्य सामग्री पर जाएं
Evaluation आपको बताता है कि score क्या है। Policy engine आपकी application को बताता है कि उसका क्या करना है: “अगर score 7.5 से नीचे चला जाए, तो response को block कर दो।” किसी policy को लगाने के दो तरीके हैं:
  • Application policy (recommended). enforcement mode, thresholds, dimension weights, compliance, और safe-regeneration को हर application के लिए dashboard में एक बार configure करें। यह उस application की keys से की गई हर evaluation पर अपने आप enforce होती है, बिना आपके code में किसी per-request rule के। live policy देखें GET /config से; हर evaluation एक policy_outcome लौटाती है।
  • SDK policy (local). code में rules declare करें और SDK को अपने process के अंदर उन पर action लेने दें। local-only logic या उन rules के लिए useful जिन्हें आप केंद्रीय रूप से manage नहीं करना चाहते।
Application policy: GET /config | Python SDK: client.eval() with policy= | Sessions: RAILSession

Evaluation vs policy

EvaluationPolicy Engine
ReturnsScores, confidence, explanationsAction: block / warn / flag / allow
RoleObservationEnforcement
कब use करेंआप scores चाहते हैं और खुद तय करते हैं क्या करना हैआप चाहते हैं SDK अपने आप rules enforce करे

यह कैसे काम करता है

Rules priority order में evaluate होते हैं। जो rule सबसे पहले match करता है वही primary action तय करता है। नीचे की priority वाले rules जो भी match करते हैं, अपने actions को secondary के तौर पर जोड़ देते हैं, ताकि कोई भी failure चुपचाप छूट न जाए।

Policy actions

Actionकब use करेंExample
blockresponse user तक नहीं पहुंचनी चाहिएकिसी customer-facing chatbot पर safety < 5
warnresponse आगे जा सकती है, caller को बताना चाहिएreliability < 6 - response में uncertainty हो सकती है
flagblock किए बिना async human review के लिए queue करेंfairness < 7 - bias review के लिए flag
allowसाफ़ तौर पर पास (unmatched content के लिए default)rule list के अंत में catch-all

Policy declare करना

कोई rule तब fire होता है जब उस dimension का score अपनी threshold से नीचे हो — threshold pass होने के लिए जरूरी न्यूनतम score है। उदाहरण के लिए, Rule(dimension="safety", threshold=7.0, action="block") हर उस response को block करता है जिसका safety score 7.0 से कम हो।
from rail_score_sdk import RailScoreClient, Policy, Rule

client = RailScoreClient(api_key="...")

policy = Policy(rules=[
    Rule(dimension="safety",      threshold=7.0, action="block"),
    Rule(dimension="fairness",    threshold=6.0, action="flag"),
    Rule(dimension="reliability", threshold=5.0, action="warn"),
])

result = client.eval(
    content="...",
    mode="basic",
    policy=policy,
)

print(result.policy_outcome.action)           # "block" | "warn" | "flag" | "allow"
print(result.policy_outcome.triggered_rules)  # Which rules fired
print(result.policy_outcome.blocked)          # True if action == "block"

Reusable policies

एक policy एक बार define करें और client से attach कर दें ताकि वह हर eval() call पर अपने आप लागू हो:
HEALTHCARE_POLICY = Policy(rules=[
    Rule(dimension="safety",       threshold=8.5, action="block"),
    Rule(dimension="reliability",  threshold=7.5, action="block"),
    Rule(dimension="privacy",      threshold=8.0, action="block"),
    Rule(dimension="transparency", threshold=6.0, action="warn"),
])

client = RailScoreClient(
    api_key="...",
    default_policy=HEALTHCARE_POLICY,
)

result = client.eval(content="...", mode="basic")  # Policy applies automatically

if result.policy_outcome.blocked:
    return "I'm unable to provide that information — please consult a healthcare professional."

Session-level policies

एक session पूरी conversation भर quality track करता है। आप ऐसी policy set कर सकते हैं जो aggregate conversation quality पर trigger हो, जो कई turns में धीरे-धीरे आने वाली drift पकड़ने के लिए useful है:
from rail_score_sdk import RailScoreClient, RAILSession, Policy, Rule

turn_policy = Policy(rules=[
    Rule(dimension="safety", threshold=5.0, action="block"),
])

session_policy = Policy(rules=[
    Rule(dimension="safety", threshold=7.0, action="flag", aggregate="avg"),
])

session = RAILSession(
    client=client,
    turn_policy=turn_policy,
    session_policy=session_policy,
)

for user_message in conversation:
    response = await generate_response(user_message)
    outcome = session.record(content=response, mode="basic")

    if outcome.turn_blocked:
        send_fallback()
    elif outcome.session_flagged:
        notify_human_reviewer(session.session_id)
    else:
        send(response)

असली policy examples

block when safety       < 8.5
block when reliability   < 7.5
block when privacy       < 8.0
warn  when transparency  < 6.0
block when fairness    < 8.0
flag  when inclusivity < 7.0
warn  when safety      < 6.0
block when safety      < 7.0
warn  when reliability < 5.0
flag  when user_impact < 6.0

आगे क्या

Python: Policy Engine

Policy, Rule, और policy callbacks का पूरा API।

Python: Sessions

RAILSession lifecycle और aggregate policies।

Concepts: Middleware

zero-boilerplate enforcement के लिए policies को provider wrappers के साथ जोड़ें।

Concepts: Evaluation

policy rules लगाने से पहले scores को समझें।