GeminiLarge-context codeLevel 3: Workflows

Where Should Your Question Go in a Long Gemini Prompt?

At the end, after all the material. Google's long context docs say this usually improves results, especially when the total is long. Put your role, rules and output format at the very start, and ask only one thing at a time.

Prompt to copy
You are reviewing code for [project]. Answer only from the code below. Cite the file path for every claim. If the answer isn't in the code, say so. Reply as [format].

<code>
<file path="[path/one]">
[contents]
</file>
<file path="[path/two]">
[contents]
</file>
</code>

Based on the code above, [one specific question].
  1. 1Role, rules, output formatat the very start or in the system instruction
  2. 2All the code or documentswrapped in consistent tags
  3. 3"Based on the information above"a bridge to the question
  4. 4One specific questionlast
The order Google's API docs recommend for long inputs. Top to bottom is the order in your prompt.

Try it now

  1. 1Take a long prompt you've used before, where the answer drifted or missed the point.
  2. 2Move your question to the very end, and add "Based on the code above" in front of it. Keep the rules at the top.
  3. 3If it contains several questions, split them, and send them one at a time in the same chat.
  4. 4You'll know it worked when the answer sticks to your question and cites specific paths.

Use it when

Any prompt where you paste a large amount of code, logs or text directly, on the API or in the app. It matters most when the material runs to thousands of lines, and answers seem to wander or ignore your request.

Skip it when

A short prompt with a sentence or two of context, where order hardly matters. Also, Google's guidance differs for a single image: the image docs say to place the text before it, while its PDF and video docs say to place the text after. Try both if the result is weak.

Why it works

Google's prompt design page says to supply the context first, put the specific question last, and connect them with a phrase such as "Based on the information above". It also says critical constraints, personas and format belong in the system instruction or at the very start. It recommends consistent delimiters, such as XML-style tags or Markdown headings, in one style throughout. On accuracy, the long context docs say that the model can extract a single fact very accurately, often up to 99%, but accuracy drops when a request has many facts to find. The docs' example is 100 facts possibly needing 100 separate requests.

Example

Say you paste 40 files of a billing service and ask, at the top, "Why are refunds failing, how are retries handled, and is there any dead code?" You've asked three different searches at once, with the question far from where the model finishes reading. Instead, set the rules at the top, put the code in <file> tags, and finish with only the refund question. Ask about retries in the next message.

Going further

If results are still weak, Google's docs suggest reordering the examples, the context and the input and comparing the output, since order can change results. Don't overdo the examples either: the same page warns that too many can make the model overfit, and it says structure and whitespace should be identical across them. For hard questions, a line such as "Think very hard before answering" can help, but it uses more thinking tokens.

Common mistakes

  • Writing a long question at the top, then pasting code beneath it with nothing after it.
  • Mixing delimiters, such as tags for one file and headings for the next. Google says to pick one style.
  • Asking for every bug in the repo in one go. The docs say accuracy falls as the number of things to find rises.
  • Burying the output format in the final line of a very long prompt, when Google says it belongs at the start or in the system instruction.

Sources

Checked 6 November 2026. Products change often, so confirm details with the vendor.

Related

Beyond the course