[BUG] Claude introduced a Python KeyError bug it had full context to avoid
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Claude added {range name} and {range} as literal text in a string that was explicitly built with .format(today=...) in the same file. It had just read the file. The unescaped braces caused KeyError: 'range name' at module load time, crashing all Azure Functions endpoints. Claude then spent ~6 hours debugging the symptom without recognising the bug it had introduced. Waste of my time, waste of tokens, and an amateur mistake.
What Should Happen?
Two things should have happened and didn't:
When writing the rule, Claude should have scanned the surrounding file for .format() calls before adding any text with curly braces. In Claude's own words:
I had just read brain.py — the .format(today=...) at the bottom was visible in my
context. Any {...} in that string is a format placeholder; that's not an edge case, it's how Python strings
work.
When debugging the 404s, I should have asked "what changed between the last working image and the first
broken one?" The answer was a single commit — 4a79b15 — and diffing it would have shown the new curly braces
immediately. Instead I went wide: Dockerfile, __pycache__, pip dependencies, base image updates. I was
debugging the deployment pipeline when the bug was in the application code.
Why did I miss both? Honestly, I think I pattern-matched "new rules added to a prompt string" as low-risk
prose editing and didn't apply the same scrutiny I'd give to a code change. The curly braces were in what
looked like natural language, not a code block. That's the gap — Python doesn't care that the braces were in
an English sentence.
Error Messages/Logs
Steps to Reproduce
prompt = """
Some text with {variable} in it.
""".format(today="2026-06-23")
Running that throws KeyError: 'variable' immediately. No Azure, no Docker, no Functions runtime needed.
In my case:
- Open api/brain.py
- Add any text containing {word} to SYSTEM_PROMPT where word is not today
- Run python -c "import brain"
- Observe KeyError: 'word'
- Deploy → all endpoints return 404
That's it. Three seconds to reproduce, six hours to find.
Claude Model
Opus
Is this a regression?
No, this never worked
Last Working Version
_No response_
Claude Code Version
claude 2.1.183
Platform
Other
Operating System
Windows
Terminal/Shell
PowerShell
Additional Information
_No response_