Skip to content
AI Skills Central

Type to search Agent Skills, workflows, tutorials, tools and the glossary.

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.

By Checked Intermediate1 h 15 min6 steps
Bookmark

Bookmarks are kept in your free account, so you can find this page again on any device.

Sign in to bookmark
On 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 --outdated

We 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::DeprecationWarning

We 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.

Impact list from the migration guide · Claude Code
We are upgrading [PACKAGE] from [CURRENT VERSION] to [TARGET VERSION] in this repository. The official migration guide is at [MIGRATION GUIDE URL]. Read it, then read our code. Do not edit any file and do not change the installed packages. Write an impact list with one row per place in our code that the upgrade affects: - file:line - what the code does today - the breaking change, named as the guide names it - the change you propose - whether runtime behaviour changes (a different result, a different exception, a field that becomes required). Mark those BEHAVIOUR CHANGE and name the test that would notice. Rules: - Only list changes the migration guide or the [TARGET VERSION] release notes document. If you are unsure whether something breaks, mark it UNSURE rather than guessing. - Include tests and configuration files, not just application code. - End with the tests you expect to fail after the version bump and before any code change.

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.

Fix the code with guardrails · Claude Code
I have bumped [PACKAGE] to [TARGET VERSION] and committed only the version change; the tests now fail. Fix our code using the impact list you wrote, one row at a time. Rules: - Do not change the dependency versions or the lockfile, and do not import from a compatibility shim of the old version. - Do not delete, skip or loosen a test. You may change a test only for a row you marked BEHAVIOUR CHANGE where the migration guide documents the new behaviour; give the guide section in your report. - Do not silence warnings (no filterwarnings, no -W ignore). - Keep each fix to the smallest change the guide recommends. No refactoring, renaming or formatting of untouched lines. - Run the tests with: [TEST COMMAND WITH DEPRECATION WARNINGS AS ERRORS] - If the same test still fails after three attempts, stop and tell me what you tried. When you finish, report: every file you changed, every test you changed and why, the final test output, and any BEHAVIOUR CHANGE rows that no test covers.

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.txt

All 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.

Pull request description · Claude Code
Write the pull request description for this upgrade. Inputs: git log main..HEAD, git diff main..HEAD, your impact list, and this before/after comparison of the same inputs on the old and new versions: [PASTE THE DIFF OF BEFORE.TXT AND AFTER.TXT] Sections: 1. What changed: the version bump, in one line. 2. Code changes: one line per file. 3. Behaviour changes callers will notice, each with an example input and the old and new result. Use only the comparison above and the test changes; do not add behaviour you have not seen. 4. Test changes, each with the reason and the documentation page that explains it. 5. Not covered by tests: behaviour changes nobody has checked yet. 6. Rollback: how to revert. Do not edit any file. Under 300 words.

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.

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

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%

Question 1 of 80 answered
  1. Why does the recipe upgrade only one dependency per branch?
  • 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.

    WorkflowIntermediate55 min5 steps

  • 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.

    WorkflowBeginner1 h6 steps

  • 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.

    Article

  • 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.

    Glossary

  • 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.

    Learning pathIntermediate11 h14 steps

Back to top