Try the demo

SyntaxWarning: invalid escape sequence '\d'

A regex that worked for years now warns, and a future Python will refuse it.

The error

script.py:4: SyntaxWarning: invalid escape sequence '\d'
  pattern = re.compile('\d+')

Why it happens

In a normal Python string, a backslash starts an escape such as \n or \t. \d isn't one, so Python keeps the backslash and, since 3.12, warns about it. Before 3.12 it was a DeprecationWarning that hardly anyone saw, and Python's docs say it will eventually be a SyntaxError.

Regular expressions and Windows paths are where it shows up, and agents write both into scripts all the time. A path is worse: in 'C:\Users', \U starts a Unicode escape, so Python stops with SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes.

The fix

Use a raw string, where a backslash is just a backslash. For paths, forward slashes work on Windows too:

pattern = re.compile(r'\d+')
path = r'C:\Users\me\project'
path = 'C:/Users/me/project'

How DMN learned it

It came up, and was fixed, in 2 of our own sessions. DMN kept the fix as one line: When passing Python via heredoc (python - <<'EOF'), write regex/backslash text as raw strings r'...' so '\d' doesn't raise SyntaxWarning: invalid escape sequence.

DMN reads your agents' past sessions on your machine. When the same error is fixed the same way in two or more of them, it keeps the fix as a one-line lesson. When the error turns up again, Claude Code is told the fix straight away, and any agent can search what earlier sessions found. How DMN keeps what agents learn.

Stop fixing the same error twice