Code generation errors with gemini-2.5-pro

We are trying to do step-by-step code generation in Python for our given problem statement. After every code step is generated, we execute the code separately (not through code execution feature) to verify it. However, we are seeing several instances of key errors in the generated code. Sharing one such instance below. Also, sharing the corresponding token usage. Our input token size is pretty large at 377K but its well within 1M limit. Has anybody faced this issue?

File “../lib/python3.11/site-packages/pandas/core/indexes/base.py”, line 3805, in get_loc
return self._engine.get_loc(casted_key)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “index.pyx”, line 167, in pandas._libs.index.IndexEngine.get_loc
File “index.pyx”, line 196, in pandas._libs.index.IndexEngine.get_loc
File “pandas/_libs/hashtable_class_helper.pxi”, line 7081, in pandas._libs.hashtable.PyObjectHashTable.get_item
File “pandas/_libs/hashtable_class_helper.pxi”, line 7089, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: ‘性別区分_ledger’

model_version=gemini-2.5-pro, input_tokens=377127, thoughts_tokens=1930, cached_tokens=None, output_tokens=20722, total_tokens=399779

Hi @Amit_Goel ,

Welcome to the Forum!
To help us investigate, could you please provide a minimum reproducible code example?

Hi @Mrinal_Ghosh, thanks for your response. Would it be possible for you to investigate based on response_id of gemini responses?

Hi @Amit_Goel, While the response_id provides some context, it isn’t sufficient for us to investigate the root cause of the issue. To help us investigate further, could you please provide a minimum reproducible code example or a detailed breakdown of your use case? This will allow us to accurately replicate the issue on our end.