# Validating YAML files

When using the [Detection Rules as Code](/scanner/using-scanner-complete-feature-reference/detections-and-alerting/detection-rules/detection-rules-as-code.md) feature, you can use the API to check that your detection rules are valid and the tests pass in Scanner before checking them into Github.

This is an API endpoint designed for use with automated processes; if you just want a fast and easy way to locally validate your detection rules, you probably want the [Scanner CLI](/scanner/using-scanner-complete-feature-reference/detections-and-alerting/detection-rules/detection-rules-as-code/cli.md) instead.

We have the following APIs for validating detection rules and running detection rule tests.

**Note:** this API is for a beta feature, and may be subject to change.

## Validate detection rule

<mark style="color:green;">**`POST`**</mark> `/v1/detection_rule_yaml/validate`

Validate a detection rule YAML.

**Example**

```bash
curl $API_BASE/v1/detection_rule_yaml/validate \
-H "Authorization: Bearer $SCANNER_API_KEY" \
-X POST \
--data-binary @src/some_detection.yaml
```

**Response**

Returns whether the detection rule `is_valid` and any `error` messages. `error` is `null` if the detection rule is valid.

```bash
{
  "is_valid":true,
  "error":null
}
```

## Run detection rule tests

<mark style="color:green;">**`POST`**</mark> `/v1/detection_rule_yaml/run_tests`

Run tests specified in the given detection rule YAML.

**Example**

```bash
curl $API_BASE/v1/detection_rule_yaml/run_tests \
-H "Authorization: Bearer $SCANNER_API_KEY" \
-X POST \
--data-binary @src/some_detection.yaml
```

**Response**

Returns `results`, a map of test names to their corresponding status (passed or failed). `results` is empty if there are no tests found in the given file.

```bash
{
  "results": {
    "Example detection rule": "Passed"
  }
}
```


---

# Agent Instructions: 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:

```
GET https://docs.scanner.dev/scanner/using-scanner-complete-feature-reference/developer-tools/api/validating-yaml-files.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
