---
title: "Fail the build on broken rules · Agent Wranglers"
url: https://agentwranglers.se/playbook/engineering/rules-as-code/build-gates
updated: 2026-10-20
licence: "All rights reserved"
---

# Fail the build on broken rules

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Required
- Chapter: [Rules as code](https://agentwranglers.se/playbook/engineering/rules-as-code)
- Rule: Make the build fail on rules that must always hold, so a broken build can never ship.
- How: Check the build output itself, not only the source. For a website, check every page for exactly one `h1` and the doctype first. Check for a title of at most 60 characters and a description of 120 to 160. Reject any inline `style=` attribute, because it breaks a strict CSP. Stop with a message naming the page. Fail on any internal link to a page that does not exist, and match every link form, such as `/about` and `https://example.com/about`. Check the markup a browser sees, so a code example that shows `style=` as escaped text does not trip the gate.
- Check: Break one rule on purpose, and the build stops. Add a link to a missing page, written once as a path and once as a full address. The build stops for both.

Example:

```js
for (const { path, title, description, html } of pages) {
  const fail = msg => { throw new Error(`${path}: ${msg}`); };
  if (!html.startsWith('<!doctype html>')) fail('doctype must come first');
  if ((html.match(/<h1[\s>]/g) || []).length !== 1) fail('needs exactly one h1');
  if (title.length > 60) fail('title over 60 characters');
  if (description.length < 120 || description.length > 160) fail('description not 120-160');
  if (/<[a-z][^>]*\sstyle=/i.test(html)) fail('inline style attribute');
}
```

```python
# The same gates in Python, failing with the page's path
for page in pages:
    if not page.html.startswith("<!doctype html>"):
        raise SystemExit(f"{page.path}: doctype must come first")
    if len(re.findall(r"<h1[\s>]", page.html)) != 1:
        raise SystemExit(f"{page.path}: needs exactly one h1")
    if re.search(r"<[a-z][^>]*\sstyle=", page.html, re.I):
        raise SystemExit(f"{page.path}: inline style attribute")
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers engineering playbook: https://agentwranglers.se/playbook/engineering/rules-as-code/build-gates`.

- Previous: [Run one check of everything before every deploy](https://agentwranglers.se/playbook/engineering/rules-as-code/run-one-check-before-every-deploy)
- Next: [Enforce the writing style in code](https://agentwranglers.se/playbook/engineering/rules-as-code/enforce-the-writing-style-in-code)
- [Rules as code](https://agentwranglers.se/playbook/engineering/rules-as-code)
