Workflow recipe
Upgrade a dependency with an AI coding agent, without surprises
Get an impact list from the migration guide, bump on a branch, let the agent fix with guardrails, then compare old and new output.
Bookmark
Bookmarks are kept in your free account, so you can find this page again on any device.
Sign in to bookmarkOn this page
To upgrade dependencies with AI, read the target version’s migration guide, get a green test run on a new branch, and ask the agent for a read-only impact list that cites the guide for every affected line. Then bump the version in its own commit, let the agent fix the code under rules that forbid loosening tests or silencing warnings, and compare the old and new versions’ output on the same inputs. The pull request lists every behaviour change you saw.
A green test suite after an upgrade proves less than it seems. When we ran this recipe on a small order service moving from pydantic 1 to pydantic 2, the agent’s fixes made all ten tests pass, yet the same inputs now produced different JSON, a numeric order id that used to be accepted was rejected, and a quantity of 2.7 that version 1 quietly cut to 2 became an error. No test covered any of that. The impact list and the old-versus-new comparison in step 5 are what caught it, and they work with any language, package manager or coding agent.
BrowserAbout 10 min
1. Pick the target version and read its migration guide
Find out what you are on and what is current, then open the project’s own migration guide and the release notes for every version in between.
uv pip list --outdatedWe saw pydantic 1.10.21 with 2.14.4 as the latest. With pip the command is pip list --outdated; with npm, npm outdated.
Note the guide’s URL; the agent needs it in step 3. Skim it for the sections that look relevant to your code and for any codemod the maintainers ship (pydantic’s guide points to bump-pydantic, which it describes as beta). Upgrade one dependency per branch. Several at once make it impossible to say which one changed a result.
TerminalAbout 5 min
2. Branch and record a green baseline
Work on a branch, and prove the tests pass before you touch anything. Run them with deprecation warnings turned into errors, so you know whether the old version was already warning you.
git switch -c upgrade/pydantic-2
uv run pytest -q -W error::DeprecationWarningWe got 10 passed. If the baseline fails, stop and fix that first, or you will not be able to tell upgrade failures from old ones. Write down the pass count.
Claude CodeAbout 15 min
3. Get an impact list before any change
Start Claude Code in plan mode with claude --permission-mode plan, so it can read but not edit, and paste the prompt with your versions and guide URL. The list it produces is your map for the rest of the recipe.
In two runs it took two to three minutes and returned 17 and 18 rows. Both marked the same untested behaviour changes: Decimal values serialised as strings, numeric ids rejected, fractional quantities rejected, one validation error instead of two, and a changed JSON schema. It predicted that every test would error at import until the @root_validator was replaced, and marked the frozen-model exception as UNSURE. Save the list; step 5 checks it.
Claude CodeAbout 15 min
4. Bump the version alone, then let the agent fix the code
Change only the version and commit it, so the version bump and the code fixes arrive as separate, reviewable commits. Run the tests once to see the failure the impact list predicted.
uv add "pydantic>=2.14.4,<3"
uv run pytest -q
git commit -am "Bump pydantic to 2.14.4 (tests fail)"Ours stopped at collection with a PydanticUserError, as predicted. Now switch Claude Code to accept edits (Shift+Tab until the status bar says so) and paste the fix prompt in the same session.
We filled the slot with uv run pytest -q -W error::DeprecationWarning. In both runs, each under a minute and a half, the agent changed two files, left the tests alone and stopped with 9 passed and 1 failed: test_orders_are_immutable expected TypeError, but pydantic 2 raises ValidationError with type frozen_instance. The guide does not say which exception is raised, so the agent asked rather than editing the test. That is the rule working.
The decision is yours. We found the new behaviour documented on pydantic’s models page under “Faux immutability”, changed the assertion to pytest.raises(ValidationError) by hand with a comment, re-ran the tests (10 passed) and committed.
TerminalAbout 20 min
5. Prove it: compare old and new output on the same inputs
Passing tests only cover what the tests check. Run a short script with real-looking inputs on both versions and diff the output. Keep the script outside the repository; put each BEHAVIOUR CHANGE row from the impact list into it as one sample.
# ../upgrade-check/compare.py
from orders.api import order_from_dict, to_public_json
samples = {
"normal": {"id": "A-1", "customer_email": "a@b.org", "placed_on": "2026-11-02",
"items": [{"sku": "ab-1", "quantity": 2, "unit_price": "9.50"}]},
"numeric id": {"id": 101, "customer_email": "a@b.org", "placed_on": "2026-11-02",
"items": [{"sku": "ab-1", "quantity": 2, "unit_price": "9.50"}]},
"fractional quantity": {"id": "A-2", "customer_email": "a@b.org", "placed_on": "2026-11-02",
"items": [{"sku": "ab-1", "quantity": 2.7, "unit_price": "9.50"}]},
}
for name, data in samples.items():
try:
print(name, "->", to_public_json(order_from_dict(data)))
except Exception as e:
print(name, "-> ERROR", type(e).__name__)Check out the old version next to the new one with a worktree, run the script in both, and diff:
git worktree add --detach ../before-upgrade main
(cd ../before-upgrade && PYTHONPATH=. uv run -q python ../upgrade-check/compare.py > ../upgrade-check/before.txt)
PYTHONPATH=. uv run -q python ../upgrade-check/compare.py > ../upgrade-check/after.txt
diff ../upgrade-check/before.txt ../upgrade-check/after.txtAll three lines differed. The normal order’s JSON lost its spaces and "unit_price": 9.5 became "unit_price":"9.50"; the numeric id and the 2.7 quantity, both accepted by version 1, now raised ValidationError. Then read the diff and search for leftovers of the old API:
git diff main --stat
git diff main -- tests/
git grep -nE "parse_obj|parse_raw|\.dict\(|\.json\(|\.copy\(|@validator|root_validator|class Config|pydantic\.v1" -- '*.py'Red flags in the diff: a test deleted, skipped or with a weaker assertion, a warning filter, a pin back to the old version, a compatibility import, or edits to files the impact list never mentioned. Ours had two code files and one test line, and the search found nothing. For each difference in the comparison, decide: keep the new behaviour and tell callers, or restore the old one in code (pydantic, for example, has a setting to coerce numbers to strings). Add a test for every one you keep.
Claude CodeAbout 10 min
6. Write the pull request from the evidence
Ask the agent to draft the description from the commits, the impact list and your diff, not from memory. Paste the output of the diff command where the slot is.
Ours returned a four-row table of behaviour changes (JSON format, numeric id, fractional quantity, frozen exception), the one test change, three impact-list rows nobody had checked yet, and a rollback naming both commits. Check that the rollback names every commit on the branch with git log main..HEAD, add the documentation link the agent could not find, and remove the worktree with git worktree remove ../before-upgrade.
Check it worked
Verification checklist
0 of 7 done
When it goes wrong
If the agent stops with one test still failing and asks what to do, that is the guardrail doing its job, not a failure. In our run the guide did not document the new exception for frozen models, so the agent refused to edit the test. Find the behaviour in the library’s own docs, then change the test yourself with a comment, or tell the agent which page allows it.
If the agent says it cannot run the tests, check that the tool it needs is on the PATH of the agent’s shell, not just yours, and that the test command is allowed. In our first attempt Claude Code could not find uv and asked for approval instead of guessing; once the tool was reachable and Bash(uv run pytest:*) was allowed, it worked through the rows in order.
If everything passes but users report changes after release, the comparison in step 5 was too thin. Add a sample for every BEHAVIOUR CHANGE row in the impact list, including the ones marked “no test notices”, and for each public output format (JSON, CSV, error messages). Then add tests that pin the behaviour you decided to keep.
If the impact list is vague or misses whole sections, the agent probably did not read the full guide. Ours said its fetch tool returned only the first 40,000 or so characters word for word and marked the rest UNSURE. Paste the relevant guide sections into the prompt, or save the guide as a file in a scratch folder and give the agent the path.
Variations
With Codex or Cursor, use the read-only or ask mode for step 3 and the agent mode for step 4, and paste the same prompts. The baseline, the separate bump commit and the comparison in step 5 are plain git and shell, so they do not change.
For a major upgrade with a codemod (such as bump-pydantic), run the codemod first in its own commit, then use step 3 to list what it left behind. The agent then fixes only the remainder, and the review is smaller.
To decide which dependencies are worth upgrading first, run audit and upgrade risky dependencies with an agent before this recipe. If your team does the same framework migration across many repositories, capture the steps in a skill instead, as in the framework migration skill recipe.
For routine patch and minor updates from a bot such as Dependabot or Renovate, skip steps 3 and 6 and keep steps 2 and 5: a green baseline and an output comparison catch most surprises. To stop the agent claiming success early, the Verification before completion skill makes it show the command output before it reports done.
Related coding agent guides
New to Claude Code? Start with the Claude Code tutorial and the glossary entry for plan mode. If the comparison shows behaviour no test covers, generate unit tests with AI for legacy code to pin it down, and read how to review AI-generated code before you approve the pull request. The AI-assisted software engineering path puts these recipes in order.
Outcome and tools
- Outcome
- A branch that upgrades one dependency, with passing tests, an old-versus-new output comparison and a pull request that lists every behaviour change.
- For
- Developers
- Variants for
- Claude Code
- Tools
- Agent Skills
Check your understanding
Upgrade a dependency with a coding agent quiz
Baselines, impact lists from the migration guide, a separate bump commit, guardrails on test changes, old-versus-new comparison and the pull request.
8 questions · pass mark 70%
Review
Related
- Audit and upgrade risky dependencies with an agent
Audit project dependencies with Trail of Bits' supply-chain-risk-auditor skill, group upgrades by risk, update one batch on a branch and prove tests pass.
- Write unit tests for legacy code with a coding agent
An agent writes characterisation tests, you check for weak assertions and prove them with mutation testing.
- Reviewing AI-written code: what to look for
The ways agent-written diffs fail, a practical review checklist, and how to set up the work so review stays manageable.
- Plan mode
An agent mode in which it reads and researches the code and proposes a plan, without editing any files until you approve the plan.
- AI-assisted software engineering
Learn AI-assisted software engineering on real repositories: set up coding agents, give them good instructions, review their diffs and run several in parallel.