---
title: "Why write your alert in query language? | Grafana Labs"
description: "See why Code mode and PromQL give you more control when building an alert rule."
---

> For a curated documentation index, see [llms.txt](/llms.txt). For the complete documentation index, see [llms-full.txt](/llms-full.txt).

# Why write your alert in query language?

**Builder mode** lets you build a query by picking metrics and filters from menus. **Code mode** lets you type PromQL yourself, which is often clearer for multi-step math like ratios.

In this path, you use Code mode to alert on QuickPizza’s **error rate**: the percentage of requests that fail. That query divides failed requests by all requests, then scales the result to a percentage. You can write that pattern directly in Code mode.

## When to reach for Code mode

Code mode is worth it when your alert needs:

- **A percentage or ratio.** For example, failed requests as a share of all requests, written as one PromQL expression.
- **Custom or multi-step math.** Patterns that are awkward to assemble from menus alone.
- **To compare two metrics.** For example, current usage against a capacity limit on a different series.
- **A query you already trust.** Paste one in from a dashboard or a teammate.

## What you’ll build

Step by step, you build every part of the rule:

- The PromQL query that measures error rate
- The threshold that decides when to fire
- A folder and labels so the alert is easy to find and organize
- How often Grafana checks the rule, and how long the problem must last before firing
- Rules for handling missing data
- The contact point and message that tell someone what’s wrong

You’ll use **QuickPizza**, a demo pizza shop you install in Grafana Cloud. The next milestone walks through that install.
