> 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/data-model-rules/data-model-rules-file-structure-and-syntax/rule.md).

# RULE

Rules are very similar to functions in modern programming languages. They are essentially named pieces of Cortex Query Language (XQL) syntax, and can be reused in the code in the `MODEL` sections, or in other `RULE` sections (recursively), by using `[rule:ruleName]`. A `RULE` is an optional data model syntax.

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

{% hint style="info" %}

### Note

For more information on the XQL syntax, see the XQL Language Reference Guide.
{% endhint %}

<details>

<summary>Points to keep in mind when writing RULE sections</summary>

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

  ```programlisting
  [RULE: common_ngfw_modeling]
  alter xdm.source.ipv4 = json_extract_scalar(actor, "$.client_ip")
  | alter xdm.network.ip_protocol = if(
      proto = 6, XDM_CONST.IP_PROTOCOL_TCP,
      proto = 11, XDM_CONST.IP_PROTOCOL_UDP,
      proto
  );
  ```
* Rules are invoked by using a `call` stage.
* Rule names are not case-sensitive.
* Rule names must be unique across the entire file.
* As section order is not significant, you do not have to declare a `rule` before using it. You can have the `rule` definition section written below other sections that use that specific rule.
* Each field used in the `MODEL` and `RULE` sections is constructed using dot notation with a specific format. However, temporary variables, which will not affect the modeling, can be used. For more information, see [Field structure](/cortex-xsiam/configure-cortex-xsiam/data-management/data-model-rules/data-model-rules-file-structure-and-syntax/field-structure.md).

</details>


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
