use_policy_to_detect
Apply a specified policy to identify and analyze violations within text inputs, supporting real-time safety and compliance monitoring in AI applications.
Instructions
Use a policy to detect violations in the provided text.
Args: policy_name: The name of the policy to use for detection. text: The text to check for policy violations.
Returns: A dictionary containing the response message and details of the detection.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| policy_name | Yes | ||
| text | Yes |
Implementation Reference
- src/mcp_server.py:196-215 (handler)The handler function for the 'use_policy_to_detect' tool. It is registered via the @mcp.tool() decorator. The function takes a policy_name and text, calls guardrails_client.policy_detect, and returns the result as a dictionary.@mcp.tool() def use_policy_to_detect(policy_name: str, text: str) -> Dict[str, Any]: """ Use a policy to detect violations in the provided text. Args: policy_name: The name of the policy to use for detection. text: The text to check for policy violations. Returns: A dictionary containing the response message and details of the detection. """ # Use policy to detect policy_detect_response = guardrails_client.policy_detect( policy_name=policy_name, text=text ) # Return the response as a dictionary return policy_detect_response.to_dict()