> For the complete documentation index, see [llms.txt](https://cortex-docs.paloaltonetworks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cortex-docs.paloaltonetworks.com/cortex-xsiam/configure-cortex-xsiam/data-management/parsing-rules/parsing-rules-file-structure-and-syntax/rule.md).

# RULE

Define reusable rules in Cortex XSIAM Parsing Rules.

{% hint style="warning" %}

### Prerequisite

Parsing Rules requires **View/Edit** RBAC permissions for **Data Management** (under **Configurations** → **Data Management**), which are the same permissions required for Dataset Management, Data Model Rules, and Event Forwarding.
{% endhint %}

Rules are very similar to functions in modern programming languages. They are essentially pieces of Cortex Query Language (XQL) syntax, tagged with a name - alias, for easier code reuse and avoiding code duplications. A `RULE` is an add-on to the Parsing Rule syntax and is optional to configure.

`RULE` syntax is derived from XQL with a few modifications, as explained in the [Parsing Rules file structure and syntax](/cortex-xsiam/configure-cortex-xsiam/data-management/parsing-rules/parsing-rules-file-structure-and-syntax.md).

{% hint style="info" %}

### Note

For more information on the XQL syntax, see [Get started with XQL](/cortex-xsiam/reference-and-developer-docs/cortex-agentix-xql/get-started-with-xql.md).
{% endhint %}

A few more points to keep in mind when writing `RULE` sections.

* Rules are defined by `[rule:ruleName]` as depicted in the following example:

  ```programlisting
  [rule:filter_issues]
  filter raw_log not contains "issue";
  ```
* Rules are invoked by using a `call` keyword as depicted in the following example:

  ```programlisting
  [rule:filter_issues]
  filter raw_log not contains "issue"; 
  [rule:use_another_rule]
  filter severity="LOW" | call filter_issues | fields - raw_log;
  ```

  This is equivalent to writing:

  ```programlisting
  [rule:use_another_rule]
  filter severity="LOW" | filter raw_log not contains "issue" | fields - raw_log;
  ```
* Rule names are not case-sensitive. They can be written in any user-desired casing, such as UPPER\_SNAKE, lower\_snake, camelCase, and CamelCase). For example, `MY_RULE=My_Rule=my_rule`.
* Rule names must be unique across the entire file. This means you cannot have the same rule name defined more than once in the same file.
* Since section order is unimportant, you do not have to declare a `rule` before using it. You can have the `rule` definition section written below other sections that use this rule.
* You can add a single tag or list of tags to the ingested data as part of the ingestion flow that you can easily query. You can add tags using both the `INGEST` and `RULE` sections.

  Adding a single tag:

  ```programlisting
  [INGEST:vendor="Check Point", product="Anti Malware", target_dataset="malware_test", no_hit= drop  , ingestnull = true ]
  alter xx = call new_tag_rule; 
  ```

  ```programlisting
  [RULE:new_tag_rule]
  tag add "test";
  ```

  Adding a list of tags:

  ```programlisting
  [INGEST:vendor="Check Point", product="Anti Malware", target_dataset="malware_test", no_hit= drop  , ingestnull = true ]
  alter xx = call new_tag_rule; 
  ```

  ```programlisting
  [RULE:new_tag_rule]
  tag add "test1", "test2", "test3";
  ```

  <div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><h3>Note</h3><p>You can also add tags using only the <code>INGEST</code> section. For more information, see <a href="/cortex-xsiam/configure-cortex-xsiam/data-management/parsing-rules/parsing-rules-file-structure-and-syntax/ingest.md">INGEST</a>.</p></div>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://cortex-docs.paloaltonetworks.com/cortex-xsiam/configure-cortex-xsiam/data-management/parsing-rules/parsing-rules-file-structure-and-syntax/rule.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
