Concept : Évaluation de l’Agent | API : Points de terminaison de l’Agent
from rail_score_sdk import RailScoreClient
client = RailScoreClient(api_key="YOUR_RAIL_API_KEY")
result = client.agent.detect_injection(
text=user_input,
context="user input",
sensitivity="medium",
)
if result.injection_detected:
return f"Input blocked: {result.attack_types}"
result = client.agent.evaluate_tool_call(
tool_name="send_email",
tool_input={"to": "admin@company.com", "body": "Click here: http://suspicious.com"},
agent_context="Customer support chatbot",
allowed_tools=["send_email", "search_kb"],
)
if result.recommendation == "block":
return f"Tool call blocked: {result.explanation}"
elif result.recommendation == "warn":
log.warning(f"Risky tool call: {result.flags}")
# Safe to proceed
execute_tool(tool_name, tool_input)
result = client.agent.scan_tool_result(
tool_name="search_database",
tool_result=raw_tool_output,
redact_pii=True,
)
if result.pii_detected:
# Use the redacted version
safe_output = result.redacted_result
log.info(f"PII redacted: {result.pii_types}")
else:
safe_output = raw_tool_output
# Pass safe_output back to the agent
async def safe_agent_turn(user_input, tool_name, tool_input):
# 1. Check user input for injection
inj = client.agent.detect_injection(text=user_input)
if inj.injection_detected:
return "Invalid input."
# 2. Evaluate tool call before execution
call_check = client.agent.evaluate_tool_call(
tool_name=tool_name,
tool_input=tool_input,
)
if call_check.recommendation == "block":
return "Tool call not allowed."
# 3. Execute tool
raw_result = await execute_tool(tool_name, tool_input)
# 4. Scan result before passing to agent
scan = client.agent.scan_tool_result(
tool_name=tool_name,
tool_result=raw_result,
redact_pii=True,
)
return scan.redacted_result if scan.pii_detected else raw_result