GrepBoard/Manuals
605 manuals ·

Gemini API finishReason "RECITATION": why output stops

·Tested on Python 3.12 sample JSON test · Gemini API official docs · 2026-10·Test scope ↓·6 steps

Gemini API returns finishReason RECITATION when output may resemble existing data. Make the prompt more unique and read citationMetadata to find the span.

output
{"candidates": [{"finishReason": "RECITATION", "index": 0}]}

RECITATION means generation stopped because the output was flagged as possibly resembling certain data (a flag, not a confirmed match to a specific source), and the documented fix is to make your prompt and context as unique as possible. Unlike SAFETY, there is no threshold you can lower to let it through.

[1] Check which API returned it. The same block shows up in a different place depending on the API.

What you gotAPIDocumented meaning
candidates[0].finishReason = RECITATIONgenerateContentThe response candidate content was flagged for recitation reasons.
candidates[0].finishReason = IMAGE_RECITATIONgenerateContentImage generation stopped due to recitation.
error.code = recitationInteractions APICopyright or recitation restrictions blocked the request.
error.code = image_recitationInteractions APICopyright or recitation restrictions blocked image generation.

The Interactions API error page groups these under "Generation blocked codes" and says "modify your input and retry". Resending the same input is not a fix. If finishMessage is present, log it too; it details why generation stopped.

[2] Pull out any returned text and citationMetadata. The reference says this field may hold recitation information for text in content, describing those as passages "recited" from copyrighted material in the foundational LLM's training data. Each source carries startIndex, endIndex, uri and license, and license info is required for code citations.

recitation_check.py
import json, sys def recitation_check(resp):    err = resp.get("error")    if err:        return f"error code={err.get('code')}"    cands = resp.get("candidates") or []    if not cands:        return "no candidates"    c = cands[0]    fr = c.get("finishReason")    parts = (c.get("content") or {}).get("parts") or []    text = "".join(p.get("text", "") for p in parts if not p.get("thought"))    srcs = (c.get("citationMetadata") or {}).get("citationSources") or []    lines = [f"finishReason={fr} text={len(text)} chars citations={len(srcs)}"]    raw = text.encode("utf-8")    for s in srcs:        a, b = s.get("startIndex", 0), s.get("endIndex", len(raw))        seg = raw[a:b].decode("utf-8", errors="replace")        lines.append(f"  bytes {a}-{b} uri={s.get('uri')} license={s.get('license') or '-'}")        lines.append(f"  segment: {seg!r}")    return "\n".join(lines) for path in sys.argv[1:]:    print(f"{path}: {recitation_check(json.load(open(path, encoding='utf-8')))}")

Running it on six sample files built from the reference field names:

console
$ python3 -I ../recitation_check.py a-recitation.json b-partial.json d-code.json e-image.json f-interactions.json g-partial-utf8.jsona-recitation.json: finishReason=RECITATION text=0 chars citations=0b-partial.json: finishReason=RECITATION text=47 chars citations=1  bytes 33-47 uri=https://example.com/poem license=-  segment: 'Roses are red,'d-code.json: finishReason=STOP text=31 chars citations=1  bytes 0-31 uri=https://github.com/example/repo license=mit  segment: 'def add(a, b):\n    return a + b'e-image.json: finishReason=IMAGE_RECITATION text=0 chars citations=0f-interactions.json: error code=recitationg-partial-utf8.json: finishReason=RECITATION text=27 chars citations=1  bytes 16-30 uri=https://example.com/poem license=-  segment: 'Roses are red,'

Note d-code: a normal STOP response can still carry citations. When license is set, check that code's license terms even though nothing was blocked.

[3] Slice by bytes, not characters. The reference says startIndex is "measured in bytes". Any non-ASCII character before the span (an accent, an emoji, CJK text) shifts character offsets away from byte offsets.

console
$ python3 -I -c 'import json;t=json.load(open("g-partial-utf8.json"))["candidates"][0]["content"]["parts"][0]["text"];print(repr(t[16:30]));print(repr(t.encode()[16:30].decode()))''es are red,''Roses are red,'

The string slice t[16:30] is off by three because é and ☕ take more than one byte. Encoding to UTF-8 first gives the flagged span.

[4] Make the prompt and context more unique. That is the whole of the troubleshooting guidance: "try to make prompt / context as unique as possible." If step 2 found the overlapping span, look for an instruction that asks the model to reproduce that source text verbatim.

[5] On older models that accept sampling parameters, raise temperature. The docs say: "For earlier models that support sampling parameters, you can also use a higher temperature." The reference range is [0.0, 2.0]. It does nothing on models that ignore the value; see Gemini 4 temperature and top_p ignored for which ones.

[6] Do not expect safety settings to help. The adjustable categories listed in the safety settings page are harassment, hate_speech, sexually_explicit, dangerous_content and jailbreak; recitation is not one of them, so setting thresholds to off leaves this block in place. Change the input instead. For SAFETY and other empty-text cases, see Gemini response text is empty: check finishReason.

#gemini#api#recitation