मुख्य सामग्री पर जाएं
Evaluation बताता है कि score क्या है। Policy engine आपकी application को बताता है कि इसके बारे में क्या करना है। आप rules declare करते हो — “अगर safety 7 से नीचे जाए, response block करो” — और SDK हर evaluated response पर automatically enforce करता है।
Python SDK: client.eval() with policy= | Sessions: RAILSession

Evaluation vs Policy

EvaluationPolicy Engine
Return करता हैScores, confidence, explanationsAction: block / warn / flag / allow
RoleObservationEnforcement
कब use करेंScores चाहिए और खुद decide करना हैSDK से automatically rules enforce करवाने हैं

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

Rules priority order में evaluate होते हैं। पहला matching rule primary action determine करता है। बाकी lower-priority rules जो match करते हैं वो secondary actions append कर देते हैं — ताकि कोई failure silently drop न हो।

Policy actions

Actionकब use करेंExample
blockResponse user तक नहीं पहुँचना चाहिएCustomer-facing chatbot पर safety < 5
warnResponse जा सकता है, caller को notify करना चाहिएreliability < 6 — response में uncertainty हो सकती है
flagBlock किए बिना async human review के लिए queue करोfairness < 7 — bias review के लिए flag
allowExplicitly pass (unmatched content के लिए default)Rule list के end में catch-all

Policy declare करना

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)  # कौन से rules fire हुए
print(result.policy_outcome.blocked)          # True अगर action == "block"

Reusable policies

एक बार policy define करो और client में attach करो — हर eval() call पर automatically apply होगी:
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 automatically apply होती है

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 करता है। आप aggregate conversation quality पर trigger होने वाली policy set कर सकते हो — gradual drift detect करने के लिए 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)

Real-world policy examples

safety      >= 8.5 : block
reliability >= 7.5 : block
privacy     >= 8.0 : block
transparency>= 6.0 : warn
fairness    >= 8.0 : block
inclusivity >= 7.0 : flag
safety      >= 6.0 : warn
safety      >= 7.0 : block
reliability >= 5.0 : warn
user_impact >= 6.0 : flag

आगे क्या करें

Python: Policy Engine

Policy, Rule, और policy callbacks की full API।

Python: Sessions

RAILSession lifecycle और aggregate policies।

Concepts: Middleware

Policies को provider wrappers के साथ combine करो — zero-boilerplate enforcement।

Concepts: Evaluation

Policy rules apply करने से पहले scores समझो।