> ## 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, और 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 है, आगे बढ़ें
  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:
      # Redacted version use करें
      safe_output = result.redacted_result
      log.info(f"PII redacted: {result.pii_types}")
  else:
      safe_output = raw_tool_output

  # safe_output को agent को वापस pass करें
  ```

  ```python Full pipeline theme={null}
  async def safe_agent_turn(user_input, tool_name, tool_input):
      # 1. User input में injection check करें
      inj = client.agent.detect_injection(text=user_input)
      if inj.injection_detected:
          return "Invalid input."

      # 2. Execute करने से पहले tool call evaluate करें
      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. Tool execute करें
      raw_result = await execute_tool(tool_name, tool_input)

      # 4. Agent को pass करने से पहले result scan करें
      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>
