I am currently using the Gemini 3.5 Flash API and encountered an issue where the returned file is empty. After retrying three times, the request still failed. I also tried reducing the size of the request file, but it still failed.
However, two other request files were processed successfully, even though those files are also quite large.
The attachments include screenshots of the API call logs and the generated file directory. All of them are files from stage2_chunk.
Below is some of the code related to the API call: from google import genai
from google.genai import types
async def generate_with_files(
self,
prompt_text: str,
*file_objects,
config: types.GenerateContentConfig | None = None,
label: str = “AI call”,
) → str:
contents = [prompt_text, *file_objects]
token_count = await self.count_tokens(*contents)
if token_count >= 0:
logger.info(“[tokens] %s → %d input tokens (model=%s)”,
label, token_count, self.model)
else:
logger.info(“[tokens] %s → count_tokens 失败,无法预估 (model=%s)”,
label, self.model)
response = await self.aclient.models.generate_content(
model=self.model,
contents=contents,
config=config or self._default_config,
)
text = response.text or “”
if not text:
_diagnose_empty_response(response, label, logger)
return text
logs:
2026-06-18 13:41:31,783 [INFO] auditmind: audit year resolved: 2025
2026-06-18 13:41:31,784 [INFO] auditmind: [Step 2] 数据标注(并发)
2026-06-18 13:41:31,784 [INFO] core.data_tagger: [Stage 1] 解析科目名称(v0.15·按 code 跨表合并)
2026-06-18 13:41:31,941 [INFO] core.account_resolver: 配置加载完成:120 个一级科目 / 148 个别名 / 19 种分隔符
2026-06-18 13:41:32,027 [INFO] core.account_resolver: 科目解析完成(v0.15·按 code 跨表合并):唯一 code 331 (journal 独有 0 / balance 独有 0 / 两表共有 331)
2026-06-18 13:41:32,027 [INFO] core.data_tagger: [Stage 1] 唯一 code 331(其中未匹配 0)
2026-06-18 13:41:32,086 [INFO] utils.gemini_client: uploading file to Gemini: account_labeling.txt (12.43 KB)
2026-06-18 13:41:32,088 [INFO] utils.gemini_client: uploading file to Gemini: stage1_labels.json (4.12 KB)
2026-06-18 13:41:32,089 [INFO] utils.gemini_client: uploading file to Gemini: stage1_input.json (25.78 KB)
2026-06-18 13:41:34,972 [INFO] utils.gemini_client: [tokens] stage1_accounts (n_unique=331) → 15322 input tokens (model=gemini-3.5-flash)
2026-06-18 13:41:34,972 [INFO] google_genai.models: AFC is enabled with max remote calls: 10.
2026-06-18 13:41:58,438 [INFO] core.data_tagger: [Stage 1] LLM 返回科目标签:331 个
2026-06-18 13:41:58,438 [INFO] core.data_tagger: [Stage 2] prefilter 动态注入年份关键字 (基准账套年=2025):2023年, 2024年, 2026年, 2027年
2026-06-18 13:41:59,731 [INFO] core.data_tagger: [Stage 2] 关键字预过滤后唯一 (科目, 摘要) 元组:2692 个
2026-06-18 13:42:00,347 [INFO] core.data_tagger: [Stage 2] 分 6 片提交 LLM(每片最多 500 个元组)
2026-06-18 13:42:00,348 [INFO] utils.gemini_client: uploading file to Gemini: summary_labeling.txt (28.71 KB)
2026-06-18 13:42:00,348 [INFO] utils.gemini_client: uploading file to Gemini: stage2_labels.json (9.20 KB)
2026-06-18 13:42:02,864 [INFO] utils.gemini_client: uploading file to Gemini: stage2_chunk_0000_request.json (108.76 KB)
2026-06-18 13:42:02,916 [INFO] utils.gemini_client: uploading file to Gemini: stage2_chunk_0001_request.json (103.23 KB)
2026-06-18 13:42:02,967 [INFO] utils.gemini_client: uploading file to Gemini: stage2_chunk_0002_request.json (106.10 KB)
2026-06-18 13:42:05,729 [INFO] utils.gemini_client: [tokens] stage2_chunk_0001 attempt 1/3 (n_tuples=500) → 57130 input tokens (model=gemini-3.5-flash)
2026-06-18 13:42:05,731 [INFO] google_genai.models: AFC is enabled with max remote calls: 10.
2026-06-18 13:42:06,037 [INFO] utils.gemini_client: [tokens] stage2_chunk_0000 attempt 1/3 (n_tuples=500) → 58851 input tokens (model=gemini-3.5-flash)
2026-06-18 13:42:06,037 [INFO] google_genai.models: AFC is enabled with max remote calls: 10.
2026-06-18 13:42:06,131 [INFO] utils.gemini_client: [tokens] stage2_chunk_0002 attempt 1/3 (n_tuples=500) → 57480 input tokens (model=gemini-3.5-flash)
2026-06-18 13:42:06,132 [INFO] google_genai.models: AFC is enabled with max remote calls: 10.
2026-06-18 13:42:47,139 [INFO] utils.gemini_client: uploading file to Gemini: stage2_chunk_0003_request.json (117.93 KB)
2026-06-18 13:42:49,775 [INFO] utils.gemini_client: [tokens] stage2_chunk_0003 attempt 1/3 (n_tuples=500) → 62833 input tokens (model=gemini-3.5-flash)
2026-06-18 13:42:49,775 [INFO] google_genai.models: AFC is enabled with max remote calls: 10.
2026-06-18 13:42:50,057 [INFO] utils.gemini_client: uploading file to Gemini: stage2_chunk_0004_request.json (112.71 KB)
2026-06-18 13:42:52,554 [INFO] utils.gemini_client: [tokens] stage2_chunk_0004 attempt 1/3 (n_tuples=500) → 62416 input tokens (model=gemini-3.5-flash)
2026-06-18 13:42:52,555 [INFO] google_genai.models: AFC is enabled with max remote calls: 10.
2026-06-18 13:43:02,004 [ERROR] utils.gemini_client: [stage2_chunk_0000 attempt 1/3 (n_tuples=500)] LLM 返回空文本,诊断信息:finish_reason=<FinishReason.RECITATION: ‘RECITATION’>; tokens(prompt=58851, candidates=None, total=58851)
2026-06-18 13:43:03,827 [WARNING] core.data_tagger: stage2 chunk 0000 attempt 1/3 返回空,5s 后重试
2026-06-18 13:43:03,827 [INFO] utils.gemini_client: uploading file to Gemini: stage2_chunk_0005_request.json (41.63 KB)
2026-06-18 13:43:06,571 [INFO] utils.gemini_client: [tokens] stage2_chunk_0005 attempt 1/3 (n_tuples=192) → 29433 input tokens (model=gemini-3.5-flash)
2026-06-18 13:43:06,572 [INFO] google_genai.models: AFC is enabled with max remote calls: 10.
2026-06-18 13:43:24,883 [INFO] utils.gemini_client: uploading file to Gemini: stage2_chunk_0000_request.json (108.76 KB)
2026-06-18 13:43:27,771 [INFO] utils.gemini_client: [tokens] stage2_chunk_0000 attempt 2/3 (n_tuples=500) → 58851 input tokens (model=gemini-3.5-flash)
2026-06-18 13:43:27,771 [INFO] google_genai.models: AFC is enabled with max remote calls: 10.
2026-06-18 13:44:22,055 [ERROR] utils.gemini_client: [stage2_chunk_0000 attempt 2/3 (n_tuples=500)] LLM 返回空文本,诊断信息:finish_reason=<FinishReason.RECITATION: ‘RECITATION’>; tokens(prompt=58851, candidates=None, total=58851)
2026-06-18 13:44:23,824 [WARNING] core.data_tagger: stage2 chunk 0000 attempt 2/3 返回空,15s 后重试
2026-06-18 13:44:38,832 [INFO] utils.gemini_client: uploading file to Gemini: stage2_chunk_0000_request.json (108.76 KB)
2026-06-18 13:44:41,712 [INFO] utils.gemini_client: [tokens] stage2_chunk_0000 attempt 3/3 (n_tuples=500) → 58851 input tokens (model=gemini-3.5-flash)
2026-06-18 13:44:41,713 [INFO] google_genai.models: AFC is enabled with max remote calls: 10.
2026-06-18 13:45:46,323 [ERROR] utils.gemini_client: [stage2_chunk_0000 attempt 3/3 (n_tuples=500)] LLM 返回空文本,诊断信息:finish_reason=<FinishReason.RECITATION: ‘RECITATION’>; tokens(prompt=58851, candidates=None, total=58851)
2026-06-18 13:45:48,137 [WARNING] core.data_tagger: stage2 chunk 0000 折半重切兜底:500 → 2 × 250(防止 RECITATION 持续触发)
2026-06-18 13:45:48,158 [INFO] utils.gemini_client: uploading file to Gemini: stage2_chunk_0001_request.json (55.00 KB)
2026-06-18 13:45:48,192 [INFO] utils.gemini_client: uploading file to Gemini: stage2_chunk_0002_request.json (53.89 KB)
2026-06-18 13:45:50,921 [INFO] utils.gemini_client: [tokens] stage2_chunk_0001 attempt 1/3 (n_tuples=250) → 35274 input tokens (model=gemini-3.5-flash)
2026-06-18 13:45:50,921 [INFO] google_genai.models: AFC is enabled with max remote calls: 10.
2026-06-18 13:45:51,231 [INFO] utils.gemini_client: [tokens] stage2_chunk_0002 attempt 1/3 (n_tuples=250) → 35361 input tokens (model=gemini-3.5-flash)
2026-06-18 13:45:51,231 [INFO] google_genai.models: AFC is enabled with max remote calls: 10.
2026-06-18 13:46:21,706 [ERROR] utils.gemini_client: [stage2_chunk_0001 attempt 1/3 (n_tuples=250)] LLM 返回空文本,诊断信息:finish_reason=<FinishReason.RECITATION: ‘RECITATION’>; tokens(prompt=35274, candidates=None, total=35274)
2026-06-18 13:46:23,301 [WARNING] core.data_tagger: stage2 chunk 0001 attempt 1/3 返回空,5s 后重试
2026-06-18 13:46:28,310 [INFO] utils.gemini_client: uploading file to Gemini: stage2_chunk_0001_request.json (55.00 KB)
2026-06-18 13:46:31,267 [INFO] utils.gemini_client: [tokens] stage2_chunk_0001 attempt 2/3 (n_tuples=250) → 35274 input tokens (model=gemini-3.5-flash)
2026-06-18 13:46:31,268 [INFO] google_genai.models: AFC is enabled with max remote calls: 10.
2026-06-18 13:47:04,472 [ERROR] utils.gemini_client: [stage2_chunk_0001 attempt 2/3 (n_tuples=250)] LLM 返回空文本,诊断信息:finish_reason=<FinishReason.RECITATION: ‘RECITATION’>; tokens(prompt=35274, candidates=None, total=35274)
2026-06-18 13:47:06,301 [WARNING] core.data_tagger: stage2 chunk 0001 attempt 2/3 返回空,15s 后重试
2026-06-18 13:47:21,297 [INFO] utils.gemini_client: uploading file to Gemini: stage2_chunk_0001_request.json (55.00 KB)
2026-06-18 13:47:24,131 [INFO] utils.gemini_client: [tokens] stage2_chunk_0001 attempt 3/3 (n_tuples=250) → 35274 input tokens (model=gemini-3.5-flash)
2026-06-18 13:47:24,131 [INFO] google_genai.models: AFC is enabled with max remote calls: 10.
2026-06-18 13:47:56,702 [ERROR] utils.gemini_client: [stage2_chunk_0001 attempt 3/3 (n_tuples=250)] LLM 返回空文本,诊断信息:finish_reason=<FinishReason.RECITATION: ‘RECITATION’>; tokens(prompt=35274, candidates=None, total=35274)
2026-06-18 13:47:58,434 [WARNING] core.data_tagger: stage2 chunk 0001 折半重切兜底:250 → 2 × 125(防止 RECITATION 持续触发)
2026-06-18 13:47:58,450 [INFO] utils.gemini_client: uploading file to Gemini: stage2_chunk_0011_request.json (27.65 KB)
2026-06-18 13:47:58,463 [INFO] utils.gemini_client: uploading file to Gemini: stage2_chunk_0012_request.json (27.49 KB)
2026-06-18 13:48:01,164 [INFO] utils.gemini_client: [tokens] stage2_chunk_0011 attempt 1/3 (n_tuples=125) → 23527 input tokens (model=gemini-3.5-flash)
2026-06-18 13:48:01,165 [INFO] google_genai.models: AFC is enabled with max remote calls: 10.
2026-06-18 13:48:01,353 [INFO] utils.gemini_client: [tokens] stage2_chunk_0012 attempt 1/3 (n_tuples=125) → 23531 input tokens (model=gemini-3.5-flash)
2026-06-18 13:48:01,353 [INFO] google_genai.models: AFC is enabled with max remote calls: 10.
2026-06-18 13:48:26,057 [ERROR] utils.gemini_client: [stage2_chunk_0012 attempt 1/3 (n_tuples=125)] LLM 返回空文本,诊断信息:finish_reason=<FinishReason.RECITATION: ‘RECITATION’>; tokens(prompt=23531, candidates=None, total=23531)
2026-06-18 13:48:27,582 [WARNING] core.data_tagger: stage2 chunk 0012 attempt 1/3 返回空,5s 后重试
2026-06-18 13:48:32,590 [INFO] utils.gemini_client: uploading file to Gemini: stage2_chunk_0012_request.json (27.49 KB)
2026-06-18 13:48:34,596 [ERROR] utils.gemini_client: [stage2_chunk_0011 attempt 1/3 (n_tuples=125)] LLM 返回空文本,诊断信息:finish_reason=<FinishReason.RECITATION: ‘RECITATION’>; tokens(prompt=23527, candidates=None, total=23527)
2026-06-18 13:48:35,319 [INFO] utils.gemini_client: [tokens] stage2_chunk_0012 attempt 2/3 (n_tuples=125) → 23531 input tokens (model=gemini-3.5-flash)
2026-06-18 13:48:35,319 [INFO] google_genai.models: AFC is enabled with max remote calls: 10.
2026-06-18 13:48:36,185 [WARNING] core.data_tagger: stage2 chunk 0011 attempt 1/3 返回空,5s 后重试
2026-06-18 13:48:41,188 [INFO] utils.gemini_client: uploading file to Gemini: stage2_chunk_0011_request.json (27.65 KB)
2026-06-18 13:48:43,939 [INFO] utils.gemini_client: [tokens] stage2_chunk_0011 attempt 2/3 (n_tuples=125) → 23527 input tokens (model=gemini-3.5-flash)
2026-06-18 13:48:43,939 [INFO] google_genai.models: AFC is enabled with max remote calls: 10.
2026-06-18 13:49:05,848 [ERROR] utils.gemini_client: [stage2_chunk_0011 attempt 2/3 (n_tuples=125)] LLM 返回空文本,诊断信息:finish_reason=<FinishReason.RECITATION: ‘RECITATION’>; tokens(prompt=23527, candidates=None, total=23527)
2026-06-18 13:49:07,672 [WARNING] core.data_tagger: stage2 chunk 0011 attempt 2/3 返回空,15s 后重试
2026-06-18 13:49:10,500 [ERROR] utils.gemini_client: [stage2_chunk_0012 attempt 2/3 (n_tuples=125)] LLM 返回空文本,诊断信息:finish_reason=<FinishReason.RECITATION: ‘RECITATION’>; tokens(prompt=23531, candidates=None, total=23531)
2026-06-18 13:49:11,991 [WARNING] core.data_tagger: stage2 chunk 0012 attempt 2/3 返回空,15s 后重试
2026-06-18 13:49:22,674 [INFO] utils.gemini_client: uploading file to Gemini: stage2_chunk_0011_request.json (27.65 KB)
2026-06-18 13:49:25,184 [INFO] utils.gemini_client: [tokens] stage2_chunk_0011 attempt 3/3 (n_tuples=125) → 23527 input tokens (model=gemini-3.5-flash)
2026-06-18 13:49:25,186 [INFO] google_genai.models: AFC is enabled with max remote calls: 10.
2026-06-18 13:49:27,008 [INFO] utils.gemini_client: uploading file to Gemini: stage2_chunk_0012_request.json (27.49 KB)
2026-06-18 13:49:29,567 [INFO] utils.gemini_client: [tokens] stage2_chunk_0012 attempt 3/3 (n_tuples=125) → 23531 input tokens (model=gemini-3.5-flash)
2026-06-18 13:49:29,567 [INFO] google_genai.models: AFC is enabled with max remote calls: 10.
2026-06-18 13:49:46,163 [ERROR] utils.gemini_client: [stage2_chunk_0012 attempt 3/3 (n_tuples=125)] LLM 返回空文本,诊断信息:finish_reason=<FinishReason.RECITATION: ‘RECITATION’>; tokens(prompt=23531, candidates=None, total=23531)
2026-06-18 13:49:46,168 [ERROR] utils.gemini_client: [stage2_chunk_0011 attempt 3/3 (n_tuples=125)] LLM 返回空文本,诊断信息:finish_reason=<FinishReason.RECITATION: ‘RECITATION’>; tokens(prompt=23527, candidates=None, total=23527)
