# How to Write a Rulebook?

<figure><img src="/files/jA0oFNkfDncW2ZmEC22c" alt=""><figcaption></figcaption></figure>

Rule Books are how you teach Stakpak to follow your way of doing things. In this tutorial, we will learn how to create our own rule books:

### Create a Rule Book from the Website

1. Go to [stakpak.dev](https://www.stakpak.dev) and sign in
2. On the left tab choose rule books and then press "Create Rule Books"

<figure><img src="/files/hq4TzS2cSErGPxwg4aEH" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/dfKz37777Nt4Cf5GcwhI" alt=""><figcaption></figcaption></figure>

3. Here all the magic happens
   1. URI: The unique link or path where the agent fetches and runs your rule book.
   2. Public: You can share the URI of your rule book, and other people will be able to use it\
      Private: Only you will have access to the rule book
   3. Description: Write a description for the rule book
   4. Tags: Add tags the agent uses to decide when to pull the rule book.
   5. Content: Add the main content of your rule book here. It's just a simple Markdown file.
4. That's it, press "Create Rule Book"

### Create a Rule Book from the CLI

1. Create a new Markdown file using this template:

```
---
uri: stakpak://my-org/deployment-guide.md
description: Standard deployment procedures for production
tags:
  - deployment
  - production
  - sop
---

# Deployment Guide

Your deployment procedures and guidelines here...
```

1. Open your terminal.
2. Navigate to the directory where the file is saved.
3. Run the following command to create/update the Rule Book:

```
stakpak rb apply rulebook-name.md
```

<figure><img src="/files/4R7lr9mvbh8FRQ0dyvGY" alt=""><figcaption></figcaption></figure>

5. To delete an existing Rule Book, run:

```bash
stakpak rb delete stakpak://my-org/old-guide.md
```

{% hint style="success" %}
Note:\
To list all the rule books you have access to type `stakpak rulebooks get`
{% endhint %}

### **Tips for Writing Stakpak Rule Books?**

* Use a clear structure
* Describe what needs to be automated rather than giving manual step by  step instructions.
* You can add requirements
  * Only run if there is Terraform code, for example
* You can ask it to follow certain standards and guidelines
  * Principle of least privilege
  * OWASP Guidelines&#x20;
  * AWS Well Architected Framework
  * Or even your internal company guidelines
* Add references


---

# 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://stakpak.gitbook.io/docs/how-it-works/rulebooks/how-to-write-a-rulebook.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.
