Topic 3 of 5 · 4 min read
Version drift and deprecated library calls
Goal: Spot code written for a different major version than the one the project pins and name the current API to use instead.
Version drift is code written for the version of a library the model remembers, not the version your project pins. Always read the lockfile first, then judge the code against that version.
Check yourself · 1 of 3
Where do you find the library version your project actually runs?
Why it matters
A model learns from text collected up to some date. Libraries keep changing after that. Tutorials and Stack Overflow answers for an old major version are far more numerous than docs for the newest one. So the model reaches for the old pattern: React class components with componentWillMount, moment instead of newer date tools, Python's datetime.utcnow(), Pydantic v1 @validator in a v2 project, or Next.js getServerSideProps in an app that uses the App Router.
The result is one of three things. The call is gone and the code crashes. The call is deprecated and prints a warning nobody reads. Or the call still works but with different behaviour, such as a new default, and the bug is silent.
How to catch it
- Find the pinned version. Look in
package-lock.json,poetry.lock,uv.lock,go.sumorCargo.lock. The manifest range (^4.0.0) is not enough. - Read the changelog or migration guide between the version the code looks written for and the version you run. Search it for the names in the diff.
- Watch the warnings. Run the tests with warnings turned into errors, for example
python -W error::DeprecationWarning, or watch the build output for deprecation notices. - Give the agent the version. Put the pinned versions and the docs link in the prompt or project instructions, so it stops guessing.
- Do not let the agent "fix" it by downgrading. If the answer to a failing call is
npm install lib@3, you have changed the project to suit the model.
Before and after
# Project pins pydantic 2.x
from pydantic import BaseModel, validator
class Order(BaseModel):
total: float
@validator("total")
def must_be_positive(cls, v):
assert v > 0
return v
validator is the version 1 style; the version 2 API is field_validator, with a required @classmethod. The fixed code:
from pydantic import BaseModel, field_validator
class Order(BaseModel):
total: float
@field_validator("total")
@classmethod
def must_be_positive(cls, v: float) -> float:
if v <= 0:
raise ValueError("total must be positive")
return v
What goes wrong
- Reading the docs for "latest" and not "pinned". You review against the wrong version.
- Accepting deprecation warnings. They are the removal notice for the next upgrade.
- Fixing the call by pinning an old version. This hides drift and leaves the project on unsupported code.
Examples
Pydantic validator
A diff adds @validator to a project on Pydantic 2. It still runs with a deprecation warning, so nobody notices for months. When the project later upgrades to a version that removes it, three models fail at import.
A changed default
An agent writes requests-style code against an HTTP client whose newer major version now follows redirects by default. The old tutorial pattern assumed it did not. The tests pass, but a login flow lands on the wrong page. The migration guide lists the change in one line.
Key points
- Models lean toward the library versions that dominate their training text, which are often older than yours.
- The lockfile, not the manifest range, tells you which version actually runs.
- Drift fails three ways: removed calls crash, deprecated calls warn, changed defaults break quietly.
- Turn deprecation warnings into errors in tests so drift shows up in CI.
- Put pinned versions and a docs link in the agent's context, and do not accept a downgrade as the fix.
Common mistakes
- Checking the code against the newest docs and not the pinned version.
- Ignoring deprecation warnings in test output.
- Letting the agent downgrade a dependency to make its old-style code run.
- Reading the version in package.json's range as the version in use.
Check yourself · 2 of 3
Why do AI assistants often write calls from an older library version?
Check yourself · 3 of 3
An agent's code fails with a removed function. It suggests installing an older major version of the library. What is the best response?
Practice items, not counted towards your mastery.
Start here
- We Have a Package for You! Package hallucinations by code-generating LLMs (opens in a new tab)PaperFree
The study that measured how often code models invent package names, across languages and models.
- Slopsquatting: how AI hallucinations are fueling a new class of supply chain attacks (Socket) (opens in a new tab)ArticleFree
Explains the attack in plain terms and what defenders can do about it.
- Concise Guide for Evaluating Open Source Software (OpenSSF) (opens in a new tab)ArticleFree
A short checklist for judging whether a package is maintained, trusted and the one you meant.
More for this topic
- package-lock.json (npm docs) (opens in a new tab)DocsFree
What the lockfile records, and why its diff is the place to see every new dependency.