Prompt shape with a retrieval tool

When retrieval lives inside the model call, your prompt is the only lever you have to steer the grounding. Two things matter most: making the URL and question explicit, and telling the model what to do when the information is not there.

src/app/api/rag/route.ts
typescript
const prompt = `Given this url: ${'$'}{remoteUrl} and this user question: ${'$'}{userInput}, I want you to give me a response based on the content of the URL. The response should be brief and concise.

 If you don't know the answer or cannot find the information in the provided URL, state that you could not find the relevant information in the provided context. Do not make up an answer.`;

Three things in one short prompt: the URL, the user question, and an explicit refusal contract. That last sentence is what stops hallucination when the page does not actually answer the question.

Ordering exercise: Order the prompt sections

Loading practice…

It helps, but it is not magic. A refusal contract meaningfully reduces made-up answers on grounded tasks, especially on newer Gemini models. It works best when paired with a URL that genuinely has the information, or cleanly does not. Gray areas are where you still need evals and testing.

Quiz: Quiz

Loading practice…