> ## Documentation Index
> Fetch the complete documentation index at: https://docs.responsibleailabs.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Python: Agent Evaluation

> client.agent - tool call evaluation, result scanning, and injection detection.

<Info>
  **Concept:** [Agent Evaluation](/concepts/agent-evaluation) | **API:** [Agent Endpoints](/api-reference/agent-tool-call)
</Info>

<CodeGroup>
  ```python Detect injection theme={null}
  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}"
  ```

  ```python Evaluate tool call theme={null}
  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)
  ```

  ```python Scan tool result theme={null}
  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
  ```

  ```python Full pipeline theme={null}
  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
  ```
</CodeGroup>
