Pin Languages & Versions

Pin the language, version, framework, and libraries in your prompt so the model stops guessing and stops inventing APIs.

TL;DR

  1. Specificity is the single biggest lever on AI code quality: name the language, version, framework, and libraries.
  2. Unspecified details become the model's guesses, which is where outdated code and invented APIs come from.
  3. State what to use and what not to use; both directions sharpen the output.

What To Pin

    Language & Version

    Name the language and its version so syntax and features match your project.

    "TypeScript 5.x, target ES2022, ESM."
    Framework & Version

    Framework APIs shift across majors; state the exact one you run.

    "Next.js 15 App Router, React 18
    server components by default."
    Libraries

    Name 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 Guessing

    Every detail you fix is one the model no longer has to invent.

    Pinned detail = one less guess
    = one less bug.
    Prevents Version Drift

    A version stops the model blending syntax from different eras of a library.

    "React 18" -> useEffect, not
    class lifecycle methods.
    Narrows The Toolbox

    Limiting allowed libraries curbs hallucinated APIs from unfamiliar packages.

    Smaller toolbox -> fewer invented calls.

Show, Do Not Just Tell

    Paste The Lockfile Lines

    Give the exact dependency versions so the model targets your reality.

    "next": "15.1.0",
    "react": "18.3.1",
    "zod": "3.23.8"
    Paste The Signature

    Show the real function or type so the model calls it correctly.

    // existing:
    export function toCents(n: number): bigint
    Name The Idiom

    Point at the project's conventions so new code fits in.

    "Match the existing style: named exports,
    no default exports."

Verify The Unknown

    Flag New Calls

    Treat any method you do not recognize as unverified until you check the docs.

    Unknown API? -> confirm it exists
    before you run it.
    Ask For Sources

    Have the model point to where an API is documented so you can confirm.

    "Which package and version exposes
    this method?"
    Let Types Catch It

    TypeScript and the compiler flag many invented members immediately.

    tsc --noEmit  # red on fake members

Tips

  1. Paste the relevant lines of your package.json or lockfile so the model matches your actual versions.
  2. When an API changed across versions, name the version explicitly so you get the right syntax.

Warnings

  1. Without a version, models blend APIs from several eras and produce code that will not run.
  2. Models invent plausible-sounding methods; constrain to real libraries and verify every unfamiliar call.

In Practice

FAQ