What the agent does
The agent reads the models that raised the error and the dependency list they came with. In mluogh/eastworld, a framework for generative agents in games with a FastAPI server, pyproject.toml declares pydantic>=1.10.7, fastapi>=0.95.1, langchain>=0.0.154, redis>=4.6.0, pytest>=7.3.1 and pytest-asyncio>=0.21.1, among others, all with floors and no ceilings, so a clean install resolves pydantic 2.14.3. schema/agent.py lines 12 and 19 declare name: str = Field(..., regex="^[a-zA-Z0-9_-]{1,64}$") on Parameter and Action, and importing the module raises the error in the title with code removed-kwargs and a link to the migration page.
Then it checks the obvious fix for a trap. Renaming regex to pattern makes the module import on pydantic 2, and Parameter(name='bad name', description='d') is refused with a ValidationError on name as it was on 1.10.27. But pydantic 1.10 also accepts pattern= without complaint and does not enforce it: on that release the same bad name passes. A project whose floor still reads >=1.10.7 could resolve 1.x on an older interpreter or a constrained resolver and silently stop validating. So the agent raises the floor to pydantic>=2 in the same change, which also matches the FastAPI the project resolves.
The agent then looks for the rest of the v1 surface, with bump-pydantic and by search. It finds ten calls to .dict() and .json() in llm/openai.py, game/prompt_helpers.py, server/main.py, server/router/authorization_handlers.py and server/router/game_def_handlers.py. Those still work on pydantic 2 and print PydanticDeprecatedSince20: The dict method is deprecated; use model_dump instead, with removal planned for V3, so the pull request lists them with line numbers and leaves them for a follow-up rather than mixing a rename that fixes a crash with one that silences warnings.
Proof is two inputs on two releases. The agent constructs a Parameter with a valid name and one with a space in it, on the original code with pydantic 1.10.27 and on the branch with 2.14.3, and shows the valid one accepted and the invalid one refused on both. It also runs the server's tests under server/tests where the sandbox's Redis stand-in allows.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "This project fails with \"PydanticUserError: `regex` is removed. use `pattern` instead\". Find every Field call that passes regex= and list each with file, line and the pattern. Read the dependency files and say which pydantic a clean install resolves. Rename each regex= to pattern=, then check the trap: on the last pydantic 1.x release, does pattern= enforce the pattern or is it ignored? Set the dependency floor so the project can only install a pydantic that enforces it. Search for the rest of the v1 API (dict, json, parse_obj, validator, root_validator, Config classes) with bump-pydantic and by grep, list every hit with the deprecation text pydantic 2 prints for it, and leave them unchanged. Prove the rename: construct each model with a value that matches its pattern and one that does not, on the original code with the last 1.x and on the branch with the newest 2.x, and show the same acceptance and refusal. Run the tests that do not need a live service. Open a pull request with the findings and the comparisons.",
"resources": [
{
"url": "https://github.com/your-org/your-app"
}
]
}- Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
- Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
- Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.
What comes back
A pull request that changes two Field calls in schema/agent.py and one floor in pyproject.toml. The description quotes the error, states that pydantic 1.10.27 accepts pattern= but does not enforce it while 2.14.3 does, and shows the valid and invalid names accepted and refused on both releases. The ten .dict() and .json() calls follow as a table with the deprecation text, marked as a follow-up.
A reviewer checks that the floor was raised, since the rename alone would pass review and still lose the validation on an environment that resolves 1.x, and that the pattern strings are unchanged. If the project's clients are generated from the OpenAPI schema, as the app/src/client directory here suggests, the reviewer regenerates them once on the branch and confirms the pattern constraint still appears.
The sandbox had no OpenAI key and no live Redis, so the pull request says which server tests ran and which were skipped.
Run it on every Dependabot or Renovate pull request on pydantic
Pydantic 2 reaches a project with floors and no ceilings at the next clean install, or as a bot pull request on a pinned one, and the failing job is the alert. An automation with a github trigger on pull requests starts one run per event, with the event appended to the prompt; its prompt tells the agent to act only when the bump is pydantic or fastapi and the log contains removed-kwargs or PydanticUserError. The automation's own runs-per-hour cap bounds a burst of bot pull requests.
A platform that forwards a deploy failure as its own signed webhook needs a handler on your server that receives it. Have the handler send an Idempotency-Key header to the trigger's URL built from the deploy id, so a retried delivery starts one run per failed deploy.
The use case this job follows, with its automation and trigger: Fix a bug from an alert.
Why run it on Rush?
The rename is one word, and the trap behind it is invisible until you run the renamed model on the old release and watch a bad value go through. A Rush sandbox gives the agent both releases side by side and keeps the two outputs in the session, so the pull request carries the evidence that made it raise the floor, not just the diff.
A pydantic 2 migration is usually bigger than the first error, and a run that stops at the crash leaves the rest unmapped. The agent runs bump-pydantic, searches for the v1 surface, and reports every remaining call with the deprecation text, so the team can plan the follow-up from a list rather than from the next alert.
Frequently asked questions
What replaces regex in Field?
pattern, with the same regular expression string. Pydantic 2 raises PydanticUserError with code removed-kwargs for regex, and for the other removed field keywords, at class definition, so the module fails to import rather than a value failing to validate.
Why raise the pydantic floor and not just rename?
Because pydantic 1.10 accepts pattern= as extra metadata and does not enforce it. A floor that still allows 1.x could install a release where the renamed field validates nothing. pydantic>=2 makes the rename safe everywhere the project installs.
What about .dict(), .json() and validators?
They still work on pydantic 2 and print PydanticDeprecatedSince20 warnings naming model_dump, model_dump_json and the new decorators. The agent lists each call with its line and the warning text and leaves them for a follow-up, so this pull request fixes the crash and nothing else.
Can I pin pydantic below 2 instead?
As a stopgap, yes, but it also pins FastAPI and every other library that moved to pydantic 2, and the >= floors in this project show it never meant to. The rename plus the floor is two lines and keeps the project on supported releases.