Persistant issue with recitation Gemini API file search

I’m using the Gemini File Search API, but very often the model responds with an error or warning related to “recitation”, and the answer gets cut off or completely withheld.

I’m not entirely sure what recitation means in this context, but I assume the model is restricting the response due to copyright or content-reuse safeguards. This is confusing, because all the files in the file store are my own documents, and I explicitly want to query and summarize them.

What’s especially puzzling is that I’ve tried the exact same prompt multiple times, and it consistently results in a recitation issue, rather than being an occasional or random failure.

Additionally, the response metadata shows a significant token spend, seemingly enough for a full answer, yet the output is still stopped prematurely.

{
  "candidates": [
    {
      "content": {},
      "finishReason": "RECITATION"
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 24,
    "totalTokenCount": 770,
    "promptTokensDetails": [
      {
        "modality": "TEXT",
        "tokenCount": 24
      }
    ],
    "toolUsePromptTokenCount": 162,
    "toolUsePromptTokensDetails": [
      {
        "modality": "TEXT",
        "tokenCount": 162
      }
    ],
    "thoughtsTokenCount": 584
  },
  "turnToken": "xyz"
}

Hi @Amin_Mokadem,

Welcome to the AI Forum! Thanks for reporting this issue.
The “RECITATION” error happens because the model is trying to copy text from your files too closely, triggering an automatic safety filter. To fix this, simply ask the model to “paraphrase” or “summarize in its own words” instead of quoting the text directly and use a higher temperature.

What if we need the exact words & content structure from the document (e.g. no phrase / text should be changed)?

Hi @Stanley_Ooi,
Thanks for your concern!
For your clarity, LLMs are generative models that generate content dynamically rather than retrieving static text like a database.
We can’t expect the exact words & content structure from the document.

So you are saying LLM are worse than OCR engine in terms of retrieving text from document?