DevTools Logo

Needle-in-a-Haystack Generator

Needle-in-a-Haystack Generator

Create deterministic context-window retrieval tests entirely in your browser

Test parameters

About

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