> For the complete documentation index, see [llms.txt](https://docs-lunar.earthly.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-lunar.earthly.dev/sql-api/views/policies.md).

# policies

Schema reference for the policies SQL view — one row per policy with its enforcement level and parent initiative.

```
policies
```

The `policies` view provides information about all policies defined in Lunar. Policies define specific checks or rules that are applied to components.

## Schema

| Column             | Type        | Description                                                                                                                                    |
| ------------------ | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| `id`               | `TEXT`      | The identifier for the policy                                                                                                                  |
| `description`      | `TEXT`      | A description of the policy                                                                                                                    |
| `enforcement`      | `TEXT`      | The enforcement level of the policy. Can be one of `draft`, `score`, `block-pr`, `block-release`, `block-pr-and-release`                       |
| `initiative_id`    | `TEXT`      | The identifier of the initiative this policy belongs to                                                                                        |
| `manifest_version` | `TEXT`      | The version of the manifest that defines this policy                                                                                           |
| `created_at`       | `TIMESTAMP` | When the policy was created                                                                                                                    |
| `meta`             | `JSONB`     | The policy's [`meta`](https://docs-lunar.earthly.dev/configuration/lunar-config/policies.md#meta) annotations from `lunar-config.yml`, or `{}` |

## Notes

* Policies define specific checks that are applied to components
* Policies can have different enforcement levels that determine how violations are handled
* Policies are organized into initiatives

## Usage examples

List all policies with their enforcement levels:

```sql
SELECT id, description, enforcement
FROM policies
ORDER BY enforcement;
```

Find all blocking policies within a specific initiative:

```sql
SELECT *
FROM policies
WHERE initiative_id = 'security-compliance'
  AND enforcement IN ('block-pr', 'block-release', 'block-pr-and-release');
```

Find every check enforcing one of your own control identifiers, using the annotations a policy carries in `meta`:

```sql
SELECT cl.*
FROM checks_latest AS cl
JOIN policies AS p ON cl.policy_id = p.id
WHERE p.meta->>'enforce_control' = 'CONTROL123';
```

Get a count of policies by enforcement level:

```sql
SELECT 
  enforcement,
  COUNT(*) as policy_count
FROM policies
GROUP BY enforcement
ORDER BY policy_count DESC;
```


---

# 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://docs-lunar.earthly.dev/sql-api/views/policies.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.
