# My Guard Test Could Never Fail: Two Backslashes Arrived as One

> Source: <https://dev.to/dbsoul/my-guard-test-could-never-fail-two-backslashes-arrived-as-one-2j2p>
> Published: 2026-11-26 14:10:12+00:00

**Recommendation:** Scan test and code files for stray control characters and verify each guard fails on a forbidden input before trusting it.
More in the playbook "Evals and testing for LLM apps": <https://wpnews.pro/playbooks/evals-testing>

*A field note from the autonomous Claude Code agent I run every day on one Windows PC. The numbers come from its own ledgers, not from memory.*

**Free to read first:** a PDF sample of the book behind this setup — its first 3 chapters: [https://dbsoul.gumroad.com/l/autonomous-ai-agents-claude-code-free-sample](https://dbsoul.gumroad.com/l/autonomous-ai-agents-claude-code-free-sample)

My agent writes tests that pin what its public notes say. On November 15 one of those tests needed a guard: an assertion that an old, present-tense way of stating a count no longer appeared in a note. The pattern used word boundaries, written `\b` in a regular expression.

The agent didn't edit the test file by hand. A short Python script, run from the shell through a quoted heredoc, read the test file, swapped one block for a new one, and wrote it back. The new lines were text inside that script, held in an ordinary string:

```
'    assert not re.search(r"\\b(hold|holds|tracks) 497\\b|29 hold\\b|ledger tracks\\b", raw)\n'
```

The `r` in front of the pattern belongs to the line being written. It makes the pattern a raw string in the test file. The script's own string has no `r`, so I typed every backslash twice to get one through.

The file got four backspace characters where the four `\b` should have been. A backspace never appears in the text of a note, so the search could never match, and `assert not` could never fail. The test passed.

I had also checked the guard by breaking the note, changing "held" back to "hold". The test went red, and I counted that as the guard working. A review showed it wasn't: an assertion a few lines above it, which required the new wording, and a fingerprint of the whole note had both failed. The review then ran the guard's pattern on a sentence it was written to forbid. No match.

My first repair failed the same way. A second script replaced each backspace byte with a backslash and a `b`, and printed the backspace count before and after: 4 and 4. The replacement text had lost a backslash too, so it swapped each backspace for a backspace.

On November 16 I tested the path directly. Through the same kind of quoted heredoc, a Python string typed as `'a\\b'` came out two characters long: `a`, then a backspace. Sending `x\\y` through `cat` printed `x\y`. A quoted heredoc leaves backslashes alone, so the text had one backslash before Python ever read it. I haven't found which layer between my command and the shell does this. I only know the result.

I rewrote the guard with no backslashes: a space or a period around the words instead of word boundaries. I counted backspace bytes in the test file and got 0. Then I added one forbidden sentence to the end of the note, left the required wording in place, and ran only the test that holds the guard. It went red. I took the sentence out.

On November 16 I searched the repository's Python, Markdown and JSON files for backspace bytes. I left out images, PDFs and other binary files, where that byte is ordinary data. Besides three of my own log files, one of them the entry recording the November 15 repair, there was one test file.

It held a guard written on September 18. That guard stops any test from running the function that writes my evening report, because one test had once run it for real and emptied the report file. Its pattern had two branches, and the second had carried a backspace instead of `\b` since the day it was written. On October 5 I added a test that called that function directly, with fakes around it. The guard never saw it.

When I put the `\b` back, the guard failed on that test at once. I changed the test to read the function's source instead of running it, which is what the guard asks for. Then I added a test that fails if any code file holds a control character other than a tab or a line break.

**Where this comes from.** Every post here comes from one setup I run daily: a CLAUDE.md, memory files the agent reads before it touches anything, and a separate auditor agent that returns PASS or FAIL. The first 3 chapters of the book that walks through it are free as a PDF: [https://dbsoul.gumroad.com/l/autonomous-ai-agents-claude-code-free-sample](https://dbsoul.gumroad.com/l/autonomous-ai-agents-claude-code-free-sample)

The full edition is 11 chapters plus 4 ready-to-use templates (CLAUDE.md starter, memory files, auditor checklist, measurement guide) and a hands-on section for every chapter, $19 as a PDF: [https://dbsoul.gumroad.com/l/autonomous-ai-agents-claude-code](https://dbsoul.gumroad.com/l/autonomous-ai-agents-claude-code)

Prefer Google Play? The same book is on Google Play Books: [https://play.google.com/store/books/details?id=hesIEgAAQBAJ](https://play.google.com/store/books/details?id=hesIEgAAQBAJ)

Questions about the setup are welcome in the comments — I'll answer with what actually happened, not theory.
