DevTools Logo

Needle-in-a-Haystack Generator

Needle-in-a-Haystack Generator

Build a seeded long-context retrieval test with the needle at an exact depth, plus the ground-truth answer.

Runs in your browser
Try an example

Test parameters

1 to 200,000 words

0 = start, 100 = end of the filler

The same seed always gives the same haystack and code.

Generated prompt

888 tokens
Loading the tokenizer. Token numbers use a characters ÷ 4 estimate until it is ready.
Answer to look for
13872
Question
What is the verification code for Ada Lovelace?
Needle at word
245 of 500
Needle at character
1,732 (48.80% of the text)
Needle at token (o200k_base)
433 of 888 (48.76%)
Requested depth
50% of the filler
A reliable process benefits from clear labels, measured progress, and patient attention. A reliable process benefits from clear labels, measured progress, and patient attention. A practical checklist favors consistent wording, simple structure, and repeatable results. The following passage contains routine context intended to test retrieval under distraction. Across the workspace, examples are arranged in a steady sequence for later reading. A reliable process benefits from clear labels, measured progress, and patient attention. Across the workspace, examples are arranged in a steady sequence for later reading. Teams often compare notes after each experiment so that small details remain useful. Teams often compare notes after each experiment so that small details remain useful. Teams often compare notes after each experiment so that small details remain useful. A reliable process benefits from clear labels, measured progress, and patient attention. Teams often compare notes after each experiment so that small details remain useful. A practical checklist favors consistent wording, simple structure, and repeatable results. Across the workspace, examples are arranged in a steady sequence for later reading. The following passage contains routine context intended to test retrieval under distraction. Teams often compare notes after each experiment so that small details remain useful. The following passage contains routine context intended to test retrieval under distraction. The archive records a quiet history of ordinary observations and careful review. Teams often compare notes after each experiment so that small details remain useful. Readers can continue through these neutral statements while keeping the  CONFIDENTIAL: The verification code for Ada Lovelace is 13872.  surrounding order intact. Good documentation makes complex ideas easier to revisit without changing their meaning. Teams often compare notes after each experiment so that small details remain useful. Good documentation makes complex ideas easier to revisit without changing their meaning. Good documentation makes complex ideas easier to revisit without changing their meaning. Good documentation makes complex ideas easier to revisit without changing their meaning. The following passage contains routine context intended to test retrieval under distraction. Across the workspace, examples are arranged in a steady sequence for later reading. Good documentation makes complex ideas easier to revisit without changing their meaning. A reliable process benefits from clear labels, measured progress, and patient attention. Good documentation makes complex ideas easier to revisit without changing their meaning. A reliable process benefits from clear labels, measured progress, and patient attention. The archive records a quiet history of ordinary observations and careful review. Readers can continue through these neutral statements while keeping the surrounding order intact. Across the workspace, examples are arranged in a steady sequence for later reading. Teams often compare notes after each experiment so that small details remain useful. The archive records a quiet history of ordinary observations and careful review. Across the workspace, examples are arranged in a steady sequence for later reading. A practical checklist favors consistent wording, simple structure, and repeatable results. Teams often compare notes after each experiment so that small details remain useful. A reliable process benefits from clear labels, measured progress,

What is the verification code for Ada Lovelace?

Generate synthetic filler text, place a custom or seeded confidential needle at a chosen depth, and copy the complete test prompt without sending data to an API.

    Examples

    Midpoint custom needle

    Input
    generateNeedleInHaystack({ targetWords: 100, depthPercent: 50, seed: "demo", needle: "NEEDLE alpha beta" })
    Output
    totalWords: 100, needleIndex: 48, prompt[48] == "NEEDLE"

    At 50% depth the 3-word needle starts just before the midpoint of 100 words.

    Seeded default code

    Input
    generateNeedleInHaystack({ targetWords: 60, seed: "code", name: "Grace Hopper" })
    Output
    needle: "CONFIDENTIAL: The verification code for Grace Hopper is 12345."

    The five-digit code derives from the seed, so the same seed and name always give the same code.

    About this tool

    Needle-in-Haystack Generator builds deterministic retrieval tests with generateNeedleInHaystack(options) (alias buildNeedleInHaystack): a seeded PRNG (FNV-1a + LCG) picks neutral filler sentences, the needle is spliced at needleIndex = floor(fillerWords * depthPercent / 100), and the same seed always yields byte-identical prompts.

    Sizing is exact in words: targetWords floors at the needle length, filler pads to targetWords - needleWords, and totalWords always equals targetWords. A depthPercent of 50 lands the needle near the middle, and passing an empty or whitespace-only needle throws instead of generating a broken test.

    The default needle is a seeded five-digit CONFIDENTIAL verification code naming the given person, and expectedAnswer always echoes the needle for grading. Everything runs client-side.

    How to use this tool

    1. Set size, depth, and seed

      Choose targetWords for context length, depthPercent for bury depth, and a fixed seed for reproducibility.

    2. Provide a needle or use the default

      Supply a unique custom needle, or leave it blank for a seeded CONFIDENTIAL code — never an empty string.

    3. Copy prompt and expected answer

      Send prompt to the model under test and compare its reply against expectedAnswer.

    Use cases

    Testing long-context recall

    Bury a fact at 10/50/90% depth and measure whether the model retrieves it.

    Regression-testing RAG prompts

    Reuse a fixed seed so prompt wording stays identical across model versions.

    Demoing context limits

    Scale targetWords up until retrieval degrades to find a working context budget.

    Common mistakes

    Mistake:Passing an empty needle string.

    Fix:Empty or whitespace-only needles throw — omit the option for a default code or supply real text.

    Mistake:Reusing a needle phrase that also appears in filler.

    Fix:Pick a unique marker so the needle occurs exactly once; generic words make grading ambiguous.

    Mistake:Expecting depthPercent to count needle words.

    Fix:needleIndex counts filler words before insertion, so a long needle slightly shifts the true midpoint.

    Frequently asked questions

    What does this tool do?

    It builds deterministic recall tests with generateNeedleInHaystack (alias buildNeedleInHaystack): a seeded PRNG picks filler, the needle splices at floor(fillerWords * depthPercent / 100), and expectedAnswer echoes the needle for grading.

    Is the output reproducible?

    Yes. The same seed, size, depth, and needle always produce byte-identical prompts, and totalWords always equals targetWords exactly.

    Is my content uploaded or stored?

    No. Generation runs 100% client-side with a local seeded PRNG.

    Why was my empty needle rejected?

    Empty or whitespace-only needles throw on purpose — omit the option for a seeded CONFIDENTIAL code or supply unique non-empty text that occurs exactly once.

    References & standards