# AI writes code for the wrong version: why it happens and how to pin versions

URL: https://opcaios.org/en/blog/ai-viet-code-sai-phien-ban
Date: 2026-10-24
Author: Lê Quốc Nghĩa

# AI writes code for the wrong version

AI writing code for the wrong library version is an error where the model generates code using an old version's approach while your project runs a newer version. The code looks reasonable, has correct syntax, uses function names that once existed, but it crashes or, worse, runs with wrong results without reporting an error. Three common forms in 2026 are:

- **Function removed or renamed:** the old command no longer exists in the new version.
- **Default value changed:** same command but different behavior.
- **Call method changed from synchronous to asynchronous:** code lacks a wait step so data comes back empty.

Example: a developer asks [ChatGPT](/tien-ich/chatgpt) from OpenAI or [Claude](/tien-ich/claude) from Anthropic to write a snippet that gets login cookies for a Next.js website. The code uses the synchronous call method from an old version, while the project has moved to Next.js 15, where this function became asynchronous according to Next.js ([Vercel](/tien-ich/vercel)). The page still builds on your personal machine with test data, but real users logging in get back empty values. Because no red warning appears, this error belongs to the silent error group and only shows up after running live, sometimes after dozens of tries.

## Why does AI often write code for old versions?

The model writes code for old versions because training data has a cutoff, and the amount of material about old versions always exceeds new ones. When a library releases a major new version, tutorials, forum posts, and sample code for that version only exist for a few weeks, while the old version has accumulated many years. The model leans toward the most common approach, and that approach usually belongs to the old version. The model also does not know what day it is today, unless the user or a tool provides it.

An example from @0xCodio on X (11/10/2026) about Blender, an open-source 3D modeling software with a Python programming interface: the name of the EEVEE renderer changed from `BLENDER_EEVEE` to `BLENDER_EEVEE_NEXT` in version 4.2, then changed back to `BLENDER_EEVEE` in version 5.0. The model learned the right change midway but got it wrong for the latest version, which according to Blender (2026) is version 5.0. The problem lies in aiming at the wrong target, not in reasoning ability.

## How serious is this?

The severity of the wrong-version error is the score drop between the old version and the new version of the same tool. According to @0xCodio's post on X (11/10/2026), the author ran a set of 30 Blender code-writing tasks across four Blender versions with ten models, totaling 1,190 answers scored by code execution. This data comes from the original author; OPCAIOS has not independently verified it, but it shows a clear trend:

| Metric | Blender 3.6 | Blender 5.0 |
|---|---|---|
| Rate of runnable code | 91% | 70% |
| Rate of model correctly stating what changed | 81% | 35% |

In addition, three task groups (compositor, boolean solver, sequencer) scored 0 points on every model on Blender 5.0. Notably, the rate of models recognizing they were using old API fell from 81% to 35%, a steeper drop than the rate of runnable code. Therefore, AI does not self-warn when writing for the wrong version.

## How do I pin the version in the prompt?

Pinning the version means writing the exact name and version number of every related tool right at the start of your request, then making AI state back which version it used for each major API. These two steps turn an implicit assumption into something you can check. A template for the start of a prompt works for most projects:

```
Environment: Next.js 15.5, React 19, Node 22, TypeScript 5.
Use only APIs that still exist in these versions.
After the code, list every API that changed from the previous major version
and state clearly which version you are targeting.
```

With [Claude Code](/tien-ich/claude-code) from Anthropic or similar tools that can read your project folder, a better approach is to let AI read `package.json`, `requirements.txt`, or version lock files itself, since the real versions live in those files. With Blender, the command `blender --version` outputs the exact version number to paste into your request. OPCAIOS estimates this takes less than 1 minute per work session but removes the most common cause of wrong-version errors.

## How to Let Machines Verify Instead of Human Eyes?

Machine verification means each piece of code AI writes must pass an automatic test, and the test stops the process when something fails. Human review of code easily misses version bugs because the code looks reasonable, while machines run tests and report directly. According to OPCAIOS's approach, a programmer using Claude from Anthropic or ChatGPT from OpenAI should set up four layers of checks in 2026, from cheapest to most expensive, each running in a few minutes:

1. **Type and compile checks:** catch non-existent functions and wrong parameters right before running, for example using TypeScript.
2. **Test run with exit codes:** buggy scripts must make the system automatically report red, not green.
3. **Unit tests for critical parts:** results match sample data.
4. **Domain-specific count checks:** with 3D models for printing in Blender, check for unclosed edges and degenerate faces with code, since render images still look nice even if the object is broken.

General principle: let machines check what machines can check, and only use human eyes for parts machines cannot measure. The detailed process for Blender is in the post [AI writes Python for Blender](/blog/ai-viet-python-cho-blender).

## Are there real examples when upgrading to Next.js 15?

A relatable example for web developers is opcaios.org itself when upgrading to Next.js 15 and React 19 in 2026: we ran into exactly this kind of error. According to Next.js's official upgrade docs, from version 15 functions like `cookies()` and the `params` parameter of pages became asynchronous and require `await`. Sample code AI generated from old habits still looks right, but test runs show errors or empty values.

Effective handling has two steps. First, declare the Next.js version in the prompt. Next, run TypeScript's type checker (from Microsoft) after each AI fix; this catches most missing `await` places before code goes to the server, so errors show up on your machine instead of when customers log in. This is OPCAIOS's experience upgrading, not general statistics.

## When Should AI Look Up Documentation Instead of Remembering?

Having AI consult official docs makes sense when a library changes fast or just released a major version. Instead of relying on stale memory, AI reads the current doc page then writes code.

A common approach is using MCP, a standard that lets AI apps read data and tools from outside. Some library providers run MCP servers that return docs matching the right version. If you're new to it, read [What is MCP?](/blog/mcp-la-gi) first. Watch security: MCP servers run code or read real data, so only install from trusted sources and grant read-only access first. If you skip MCP, the manual way still works well: open the library's upgrade guide, paste the breaking changes section into your request, then tell AI to apply that list exactly. The list of changes written by developers is more trustworthy than the model's memory.

## What Checklist Helps AI Code Match the Version?

A checklist is a seven-step list done in order to make AI-written code match the version you're using, whether Next.js, Python, Blender or other tools. Each step takes a few minutes by experience with Claude from Anthropic, but blocks a specific group of errors, from wrong function calls to silent wrong results:

1. Write the exact version of every library in the prompt, or have AI read your lock file.
2. Ask AI to list changed APIs and the version you're targeting.
3. Set config so real errors actually stop the process.
4. Run type checker or compiler after each fix.
5. Write at least 1 automatic test for important results.
6. When wrong, ask AI to patch just the bad part and return a diff, not rewrite the whole file.
7. With new or fast-changing libraries, have AI check current docs before writing, like through MCP.

## Frequently Asked Questions

### Why does AI-written code have bugs even though it looks correct?
The code looks correct because it matches common usage patterns in the data the AI learned from. Bugs only appear when running on a newer version, where function names or calling conventions have changed.

### Is it enough to specify the version in the prompt?
Not enough. Specifying the version helps reduce bugs but doesn't eliminate them completely. You need to add a step to test-run or type-check so the machine confirms the code actually runs on that version.

### Should I let AI read documentation or rely on the model's memory?
For stable libraries, the model's memory is usually sufficient. For libraries that just had a major release or change rapidly, you should have AI read current documentation, for example through MCP or by pasting relevant documentation pages into the request.

### Does version error only happen with one specific AI model?
No. According to benchmark tests on ten models cited by @0xCodio, the trend of performance drop on newer versions appears across many different models. Choosing a different model doesn't replace pinning the version and verifying it.

### Do non-programmers need to care?
Yes, if you ask AI to write scripts to automate your work, because a script with version bugs can run and produce wrong results without raising an error. Do two things: ask AI which version it's targeting, then request a test run with sample data before using it for real. For example, an office worker asking ChatGPT from OpenAI to write a script to process spreadsheets should clearly specify which Python and Excel versions they're using. To learn how to use AI safely in business, see [the AI application training course](/services/dao-tao-ung-dung-ai).

*Source: benchmark data and Blender examples from [@0xCodio's post on X](https://x.com/0xCodio/status/2109275834984915150) (11/10/2026), not independently verified; Next.js 15 example is OPCAIOS's experience.*
