Pin Languages & Versions
Pin the language, version, framework, and libraries in your prompt so the model stops guessing and stops inventing APIs.
TL;DR
- Specificity is the single biggest lever on AI code quality: name the language, version, framework, and libraries.
- Unspecified details become the model's guesses, which is where outdated code and invented APIs come from.
- State what to use and what not to use; both directions sharpen the output.
What To Pin
Language & VersionName the language and its version so syntax and features match your project.
"TypeScript 5.x, target ES2022, ESM."Framework & VersionFramework APIs shift across majors; state the exact one you run.
"Next.js 15 App Router, React 18
server components by default."LibrariesName the libraries you want and forbid the ones you do not.
"Use zod for validation.
Do not add new dependencies otherwise."Why It Works
Removes GuessingEvery detail you fix is one the model no longer has to invent.
Pinned detail = one less guess
= one less bug.Prevents Version DriftA version stops the model blending syntax from different eras of a library.
"React 18" -> useEffect, not
class lifecycle methods.Narrows The ToolboxLimiting allowed libraries curbs hallucinated APIs from unfamiliar packages.
Smaller toolbox -> fewer invented calls.Show, Do Not Just Tell
Paste The Lockfile LinesGive the exact dependency versions so the model targets your reality.
"next": "15.1.0",
"react": "18.3.1",
"zod": "3.23.8"Paste The SignatureShow the real function or type so the model calls it correctly.
// existing:
export function toCents(n: number): bigintName The IdiomPoint at the project's conventions so new code fits in.
"Match the existing style: named exports,
no default exports."Verify The Unknown
Flag New CallsTreat any method you do not recognize as unverified until you check the docs.
Unknown API? -> confirm it exists
before you run it.Ask For SourcesHave the model point to where an API is documented so you can confirm.
"Which package and version exposes
this method?"Let Types Catch ItTypeScript and the compiler flag many invented members immediately.
tsc --noEmit # red on fake membersTips
- Paste the relevant lines of your package.json or lockfile so the model matches your actual versions.
- When an API changed across versions, name the version explicitly so you get the right syntax.
Warnings
- Without a version, models blend APIs from several eras and produce code that will not run.
- Models invent plausible-sounding methods; constrain to real libraries and verify every unfamiliar call.
In Practice
A request for form validation, first underspecified, then pinned to a real stack. The pinned version gets the correct library idiom and avoids invented helpers.
- The underspecified prompt leaves the library, version, and style to chance.
- The pinned prompt names the framework, the validation library, and the versions.
- A 'no new dependencies' rule keeps the answer inside the chosen toolbox.
- Pasting one real type anchors the output to code that already exists.
# UNDERSPECIFIED
Add validation to my signup form.
# PINNED
Stack: Next.js 15 (App Router), React 18,
TypeScript 5.x, zod 3.23 for validation.
Do not add new dependencies.
Existing type:
type SignupValues = { email: string; password: string };
Task: write a zod schema for SignupValues
(email must be valid, password >= 8 chars) and a
`validateSignup(values)` that returns
{ ok: true } | { ok: false; errors: Record<string,string> }.
Return only the schema and the function.FAQ
Libraries change their APIs between versions. Without a version, the model averages over everything it has seen and may mix old and new syntax. Saying 'React 18' or 'Tailwind v4' pins it to one consistent API.
Constrain the toolbox. Say 'use only the standard library', 'use only these dependencies', or paste the real module's exports. Then verify any call you do not recognize against the docs before trusting it.
Both help. 'Use date-fns, not moment' removes ambiguity in one line. Positive constraints steer toward your stack; negative constraints rule out tempting wrong answers.
At minimum the language and version (TypeScript 5.x), the framework and version (Next.js 15, React 18), the styling approach (Tailwind v4, CSS Modules), the runtime (Node 20), and whether you use ESM or CommonJS.