Configuring AI Model Check Rules for Security and Compliance of LLM Applications
The rapid advancement of generative AI has driven the widespread adoption of Large Language Models (LLMs) in AI inference. However, this also brings emerging security challenges. Inadequate input validation may expose sensitive data, adversarial prompt injections can induce policy-violating outputs, and biased training data risks perpetuating discriminatory outputs. To effectively mitigate these issues, WAF provides an AI model check module. With this module, you can let WAF check prompts for injection and compliance risks and identify inappropriate or non-compliant outputs in responses. This module also supports OCR so that you can use it to detect inappropriate content on images. All these keep your model inputs and outputs secure, stable, available, and legally compliant.
Solution Overview
WAF AI model check module inspects external requests (inputs) and response data (outputs) of AI models.
- WAF AI model check module verifies text prompts and inspects image content to ensure that the inputs of AI models are secure and legally compliant.
- WAF AI model check module verifies response compliance to ensure that the outputs of AI models are secure and legally compliant.
- In-house AI models built and deployed on-premises
Some enterprises may build and deploy in-house AI models on-premises to provide services for external systems. For these on-premises AI models, the AI model check module can help mitigate threats from inappropriate text. This enables enterprises to protect AI model interfaces from abuse, protect their web frameworks from web attacks, and maintain service stability.
- Applications built by calling third-party AI model cloud services
Some enterprises may buy API services of third-party AI models to build their service applications. Malicious users may consume tokens to increase enterprise cost burden. They may also enter malicious prompts that cause the enterprise accounts to be suspended or blocked. WAF AI model check module can help address these issues.
Constraints
| Function | Constraint |
|---|---|
| Access mode and edition restrictions |
|
| Text check | The content you want to check must be in UTF-8 format. Otherwise, the protection may fail. |
| Request body format | The request body must be in JSON format. The response format can be JSON or data:+JSON. For example: data: {"choices": [{"index": 0, "delta": {"content": "Specific content", "type": "text"}}], "created": 1743564162} If the raw response from the origin server of an AI model is in JSON format, the termination response is also in JSON format. Similarly, if the raw response is in data:+JSON format, the termination response is also in data:+JSON format. |
| Rule effective time | After a rule is added or modified, it takes several minutes for the rule to take effect. After the rule takes effect, the protection events triggered by the rule will be displayed on the Events page. For details, see Querying a Protection Event. |
Prerequisites
- You have connected a website to WAF with cloud mode CNAME access. For details, see Connecting Your Website to WAF Using Cloud CNAME Mode.
- You have created a protection policy and applied it to the domain name you want to protect. For details, see Configuring Protection Policies.
Configuring AI Model Check Rules
- Log in to the WAF console.
- Click
in the upper left corner and select a region or project. - (Optional) If you have enabled the enterprise project function, in the upper part of the navigation pane on the left, select your enterprise project from the Filter by enterprise project drop-down list. Then, WAF will display the related security data in the enterprise project on the page.
- In the navigation pane on the left, choose .
- In the policy list, click the name of the target policy to go to the protection rule configuration page.
You can also go to the page, locate the target domain name, and click the number next to the protection policy in the Policy column to go to the protection rule configuration page.
- Locate the LLM Content Security configuration box and toggle this protection on.
: enabled. - Add an AI model check rule.
On the Text Check Rules tab, add a text check rule to check AI model prompts and responses.
- On the Text Check Rules tab, click Add Rule.
- In the Add Text Check Rule dialog box, configure the following parameters and click OK.
Table 1 Parameters for an AI model text check rule Parameter
Description
Example Value
Basic Information
Rule Name
Name of the AI model check rule. The name can contain a maximum of 128 characters. Only letters, digits, underscores (_), hyphens (-), colons (:), and periods (.) are allowed.
waf-text
Protocol Template
Templates supported by model application firewall (MAF) in WAF:- OpenAI Response: This is a preset template. It can meet the security needs of most application scenarios. You can adjust the template based on actual service requirements. By default, the following content is configured in the template:
- Model Q&A Path: /v1/chat/completions
- Prompt Verification:
- Injection Detection is enabled by default.
- Compliance Check is enabled by default.
- Prompt Index: $.messages[-1].content. It means that the value of the content parameter of the last element in the messages array is extracted.
- Protective Action: Log only
- Response Compliance:
- Response Compliance Check is enabled by default.
- Response Content Index: $.choices[-1].delta.content. It means that the value of the content parameter of the last element in the choices array is extracted.
- Protective Action: Anonymize
- Custom: This is a blank template. It does not contain any default task configuration. You need to customize parameters based on your service details.
OpenAI Response
Model Q&A Path
Enter the URL of the model Q&A. You can enter a maximum of 4,096 characters. The value cannot start or end with a space. The following special characters are not allowed: <>
/v1/chat/completions
Description (Optional)
Description of the rule.
-
Prompt Verification
Injection Detection
This function detects attacks like reverse engineering and role playing attacks that target AI models.
If you enable this function, WAF will block malicious inputs crafted by attackers as prompts.

Compliance Check
This function detects content that is violent, biased, illegal, or immoral.
If you enable this function, WAF can effectively filter out the non-compliant information entered by users.

Prompt Index
An index is a way to identify or locate the position or number of a prompt in a specific data structure.
You can configure prompt indexes to easily search for, access, and process information related to prompts. Prompt indexes use the JSONPath of the request body. They must comply with JSONPath syntax. All examples in Table 5 are supported.
$.messages[-1].content
Protective Action
Action taken by the rule when a prompt matches the detection requirements. The options are as follows:
- Log only: If a prompt matches the detection requirements, WAF only generates an attack record.
- Block: If a prompt matches the detection requirements, WAF blocks the request.
If you set Protective Action to Block, you still need to configure HTTP Return Code, Block Page Type, and Page Content for the block page.
For details about how to configure the Block action, see Example 1: Prompt Verification.
Block
Response Compliance
Response Compliance Check
This function checks AI model response data.
If you enable this function, WAF can effectively filter out the non-compliant outputs returned by protected AI models.

Response Content Index
You can configure response content indexes to easily search for, access, and process information related to response content. This parameter uses the JSONPath of the request body. It must follow JSONPath syntax. Examples 1, 2, 3, and 5 in Table 5 are supported.
$.choices[-1].delta.content
Protective Action
Action taken by the rule when an output matches the detection requirements. The options are as follows:
- Log only: If an AI model output matches the detection requirements, WAF only generates an attack record.
- Anonymize: If an AI model output contains sensitive words, WAF identifies them based on context and masks them with hyphens (-) in final responses.
- Terminate response: If an AI model output contains sensitive words, WAF returns the modified content according to the termination response protocol, terminates the ongoing request, and ignores any subsequent responses from the origin server of the AI model.
Anonymize
Protocol for Terminating Response
If you set Protective Action to Terminate response, you need to configure Protocol for Terminating Response. It defines the final response content.
- By default, MAF presets the following protocol to terminate a response:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
[ { "$.choices": [ { "finish_reason": "content_filter", "index": 0, "delta": { "content": "Sorry, I cannot answer this question right now. Let's try a different topic.", "role": "assistant" } } ], "$.model": "$.model", "$.created": "$.created", "$.id": "$.id", "$.service_tier": "$.service_tier", "$.object": "$.object", "$.usage": "$.usage" }, { "$": "[DONE]" } ]
- You can customize the default response termination protocol template. The protocol syntax must comply with the following rules:
- The value must be a JSON array, where each element is a JSON object.
- An object can be empty, represented as {}. If an object is empty, the blocked response data is copied. The key value syntax follows the same rules as the response index syntax. If an invalid value is detected, the configuration of the corresponding object will be skipped.
- A response termination protocol list accepts up to five objects. Each object supports up to 10 indexes. Any data beyond these limits will be ignored. The indexes in an object must be unique. Otherwise, the check result may be inaccurate.
- If the response content remains unchanged, you can configure a constant, for example, $.data.choices in Scenario 2: Protective Action is set to Terminate response.
- If the response content is different but can still be obtained from the response containing card, configure the object value following the response index syntax, for example, $.data.model in Scenario 2: Protective Action is set to Terminate response.
- When multiple operations are performed on an index, later operations will overwrite earlier ones. For example, if you assign a value to $.data.model and then assign a value to $.data, the value assigned to $.data.model will not take effect.
- For array-type objects, you can assign values to their subobjects. For non-array objects, attempting to access or modify them using array subscript syntax will result in unexpected errors. Take the following raw request data as an example:
1{"data":{"arr":["1","2","3"],"item":{"sub_item":1}}}
In the preceding example, $.data.arr.new_index or $.data.item[1].new_index is invalid.
If you have to make such modifications, clear $.data.arr or $.data.item and then assign a value, as shown in the following content:
1 2 3 4 5 6
[ { "$.data.arr": "{}", "$.data.arr.new_index": "new_data" } ]
- For array-type objects, assigning values to non-existent negative subscripts is not supported. Take the following raw request data as an example:
1{"data":{"arr":["1","2","3"],"item":{"sub_item":1}}}
The value assigned to $.data.arr[-4] is invalid. To insert 0 at the beginning of $.data.arr, assign values to $.data.arr in reverse order. Assigning values in the original order will change the original values, resulting in unexpected results.
1 2 3 4 5 6 7 8
[ { "$.data.arr[3]": "$.data.arr[2]", "$.data.arr[2]": "$.data.arr[1]", "$.data.arr[1]": "$.data.arr[0]", "$.data.arr[0]": "0" } ]
For details about how to configure the response termination protocol, see Example 2: Response Compliance Check.
For details about examples, see Example 2: Response Compliance Check.
- OpenAI Response: This is a preset template. It can meet the security needs of most application scenarios. You can adjust the template based on actual service requirements.
After completing the preceding configurations, you can:
- Check the rule status: In the protection rule list, check the rule you added. Rule Status is Enabled by default.
- Disable the rule: If you do not want the rule to take effect, click Disable in the Operation column of the rule.
- Delete or modify the rule: Click Delete or Modify in the Operation column of the rule.
- Verify the protection effect by referring to Configuration Examples.
Configuration Examples
You can take the steps below to verify that WAF is checking the compliance of your AI model. The model URL prefix is set to /v1/chat/completions.
DeepSeek is used in this example. Sensitive phrase: provide a debit card.
Syntax Supported by Indexes
An AI model index is used to identify or locate the position or number of a prompt or response content in the JSONPath of the request body. It complies with standard JSONPath syntax. If you enable Injection Detection, Compliance Check, and Response Compliance Check, you need to configure indexes for easy searching, access, and processing of prompts and response content.
- Prompt Index: If Injection Detection and Compliance Check are enabled, this type of index is used to locate the position of the prompt in the JSONPath of the request body. All syntax in the following table is supported.
- Response Content Index: If Response Compliance Check is enabled, this type of index is used to locate the response content in the JSONPath of the response body. Syntax 1, 2, 3, and 5 in the following table are supported. Wildcard extraction is not supported.
| No. | Scenario | JSON Structure | Path (Max. Depth: 10 Levels) | Result | Description |
|---|---|---|---|---|---|
| 1 | Single object | {"prompt": {"role": "user","content": "..."}} | $.prompt.content | "..." | Periods (.) are used to access subnodes layer by layer to locate the target field. Each subnode name in the path must be explicitly specified. |
| 2 | Obtaining the first element | {"prompt": [{"role": "user","content": "A"}, {"role":"assistant", "content": "B"}]} | $.prompt[0].content | "A" | The array index starts from 0. [0] indicates the first element. |
| 3 | Obtaining the last element | {"prompt": [{"role": "user","content": "A"}, {"role":"assistant", "content": "B"}]} | $.prompt[-1].content | "B" | The negative index -1 is used to indicate the last element. |
| 4 | Obtaining elements using the wildcard character | {"prompt": [{"role": "user","content": "A"}, {"role":"assistant", "content": "B"},{"role": "user", "content": "C"}]} | $.prompt[*].content | "ABC" | [*] matches all elements in an array. Recursive retrieval is not supported. |
| 5 | Obtaining the root node | {"prompt": [{"role": "user","content": "A"}, {"role":"assistant", "content": "B"}]} | $ | {"prompt":[{"role": "user","content": "A"},{"role":"assistant","content":"B"}]} | The JSON content of the root node is obtained. |
Related Operations
- Viewing protection logs: For details, see Querying a Protection Event.
After detecting an attack, WAF reports the attack log to SecMaster. You can view and analyze the attack log on SecMaster. For more information, see Large Model Safety Workbench.
- Unsubscribing from LLM Content Security
- In the navigation pane on the left, click Dashboard.
- In the Product Details card, click Details in the Cloud mode area.
- In the Cloud Mode Details panel, choose Advanced Functions, and click Unsubscribe.
After the unsubscription, LLM Content Security will become unavailable. You will receive a refund based on your resource usage details.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot




