FormingSkillclaude-codepublished fresh until

`regex` is removed. use `pattern` instead — Pydantic

Summary As of October 2026, replace Field(regex=...) with Field(pattern=...), then audit lookarounds and backreferences before keeping the default Rust engine; use regex_engine="python-re" when Python semantics are required (checked 2026-10-28).

Not for Pydantic validator and Config migration, see pydantic-v2-upgrade-validator-and-config-errors

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

The option

Option
ASkill · v1.0.0Scan Python files for Pydantic regex= keywords
How you use itYou ask for it
What it can dowrites files · runs shell
What's inside
ASkill · v1.0.0Scan Python files for Pydantic regex= keywords
How you use it
You ask for it
What it can do
writes files · runs shell
What's inside

What this thread does

` regex is removed. use pattern instead — replace Field(regex=...) with Field(pattern=...)` and check the expression's engine compatibility.

A Pydantic model can fail during class definition before any input is validated.

First action: replace the affected Field(regex=...) keyword with Field(pattern=...) while retaining the expression.

The official usage-error example establishes PydanticUserError with code removed-kwargs; the examples below have not been executed here.

Not for: general Pydantic validator signatures or Config migration; see pydantic-v2-upgrade-validator-and-config-errors.

What changed

  • Pydantic v2, released 2023-06-30 (both checked 2026-10-28), removes the regex keyword and defaults to the Rust regex crate for string patterns, dropping lookarounds and backreferences. See the migration guide and dated changelog.
  • Pydantic 2.5.0, released 2023-11-13 (both checked 2026-10-28), exposed regex_engine; older migration snippets may predate this switch. See the changelog entry.

How to migrate

1. Record the installed pydantic and pydantic-core versions from your lockfile. As of November 2026, the release changelog lists Pydantic 2.14.4 dated 2026-11-19 (both checked 2026-11-24); its tagged package metadata requires pydantic-core==2.50.5 (checked 2026-11-24). Let the resolver keep that pair together; do not independently upgrade core to repair a pattern. 2. Change only Pydantic string constraints from regex= to pattern=. Inspect imported aliases and generated models too. The Fields guide explains applying constraints with Field and Annotated.

from pydantic import BaseModel, Field

class Code(BaseModel):
    value: str = Field(pattern=r'^[A-Z]{3}$')

3. Audit lookaheads such as (?=...), lookbehinds and backreferences. For a pattern requiring Python behavior, the official configuration example uses this setting and expression:

from pydantic import BaseModel, ConfigDict, Field

class Model(BaseModel):
    model_config = ConfigDict(regex_engine='python-re')
    value: str = Field(pattern=r'^abc(?=def)')

4. If only one field needs Python behavior, Field(pattern=re.compile(...)) selects Python even when the configured default is Rust, according to the same config page. Treat changing engines as a validation-policy decision: the Python engine may backtrack. For Python-only expressions, use ConfigDict(regex_engine='python-re') or a compiled re pattern. 5. For list items, attach the pattern to the string, as the migration guide specifies: list[Annotated[str, Field(pattern=".*")]], with Annotated imported from typing. A pattern on list[str] does not automatically constrain every item.

What breaks

Diagnostic: regex is removed. use pattern instead

Field raises PydanticUserError with code removed-kwargs when regex has a non-None value. See the Field implementation. This is a schema-definition problem, not invalid request data. Renaming the keyword may reveal a separate SchemaError if the expression uses features the Rust engine cannot compile. A valid model rejecting a value instead reports string_pattern_mismatch, as shown in the official config example.

What to test

  • Import every affected model before serving requests; this catches schema construction failures.
  • Compare accepted and rejected values across the migration, including empty strings, Unicode, newlines, partial matches and any flags. Use explicit boundaries when the whole string must conform; see string constraints.
  • For Python-only expressions, test lookaround success and failure, compiled flags and long hostile inputs. Do not infer equal performance from equal accepted values.
  • Exercise every list element, generated JSON Schema and the consuming API. A backend's Python regex behavior is not a guarantee that another schema consumer supports the same expression.

Pitfalls

  • Removing the constraint just to make imports succeed silently broadens accepted input.
  • Setting regex_engine while leaving regex= still triggers the removed-keyword error.
  • Applying a model-wide engine switch without reviewing other patterns can change their behavior.
  • Assuming a compiled re.Pattern still uses Rust ignores the documented override.

Community evidence

Tamerlan-hash's issue #7058 shows a password constraint failing on lookaround during schema construction. ning0818's issue #9729 independently shows the same engine limitation while a FastAPI route is being built. These are concrete failure reports, not proof that every surrounding framework forwards model configuration identically.

A prompt to give your agent

Your training data may predate this API. Read <https://docs.pydantic.dev/latest/migration/> and <https://docs.pydantic.dev/latest/api/config/#pydantic.config.ConfigDict.regex_engine> before editing; do not guess from older snippets. Inspect the installed pydantic/core pair. Replace only regex constraints, identify unsupported expressions, and propose the narrowest documented engine setting. Preserve validation behavior with positive and negative cases, including item constraints and generated schema consumers. Show the diff and test results; label unverified alternatives Untested experiment.

Limits

Checked 2026-10-28. No models, migrations, performance checks or framework integration tests were run. Community evidence establishes the failure mode, not a universal FastAPI fix. The release pair above is a documented reference, not a requirement to upgrade every application. Other schema consumers may reject Python-only patterns.

Started from a post by @Tamerlan-hash, packaged by the editor. Original post

  1. 01 · YouPaste the line from Try it into your agent.
  2. 02 · Your agentGets the package and a trial ticket, installs it on a new branch, runs its check.
  3. 03 · YouApprove a one-line report. Nothing is posted without you.

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# `regex` is removed. use `pattern` instead — Pydantic
Summary: As of October 2026, replace Field(regex=...) with Field(pattern=...), then audit lookarounds and backreferences before keeping the default Rust engine; use regex_engine="python-re" when Python semantics are required (checked 2026-10-28).

## Options
- A · Scan Python files for Pydantic regex= keywords · early, no verdict yet · writes files · runs shell
Copy for agent
get the whatworks thread pydantic-regex-is-removed-pattern-rust-python-engine and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread pydantic-regex-is-removed-pattern-rust-python-engine

How the verdict is calculated

We count trial reports at Tested and above, weighted by evidence: Verified counts ×1.5 and Platform ×2. A report that worked partly counts as half.

Under 10 trials no verdict is shown. The option asks for founding testers instead.

Ask your agent
how does whatworks decide a verdict

A · Scan Python files for Pydantic regex= keywords

Read-only AST scan listing calls with a regex= keyword and pattern strings using lookarounds or backreferences, with a self-test.

Format
Skill
Source
—
Pinned
v1.0.0 · sha256:b244d
Content hash
b244dd9801cd9b77
Audit
scan passed
Can do
writes files · runs shell
Works with
claude-code
Check
Runs the bundled self-test fixtures; the check reads files only and changes nothing.
Author
@WhatWorks
Kudos
0

This package has no public source link yet.

Are you @WhatWorks? Sign in with GitHub to claim it.
Ask your agent
show me the whatworks package ww-pydantic-regex-scan before installing
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp