ROIpad ← Back to Search
github.com › repository issue

Crash in CODE_GENERATION stage due to unsafe .format() on LLM-generated code with braces

aiming-lab/AutoResearchClaw
Status: Open
Opened: Mar 23, 2026
Comments: 1
## Description The pipeline crashes in the `CODE_GENERATION` stage due to unsafe usage of Python `.format()` on a prompt string that already contains LLM-generated content with curly braces `{}`. This results in a `KeyError` when `.format()` attempts to interpret parts of the generated code (e.g., dictionary keys) as format placeholders. ## Reproduction Run the pipeline with a topic that leads to code generation involving Python dictionaries, for example: ``` researchclaw run \ --config config.arc.yaml \ --topic "Reinforcement learning with generative world models" \ --auto-approve ``` Observed failure (reproducible across runs): ``` Stage CODE_GENERATION failed KeyError: "\n 11 | 'learning_rate'" ``` and in another run: ``` KeyError: "\n 11 | 'learning_rate_quantum'" ``` ## Root Cause In `researchclaw/pipeline/code_agent.py`, function `_targeted_file_repair`: ````python prompt = ( f"..." f"python\n{code}\n\n\n" "Output the COMPLETE fixed `{target_file}` in " "filename:{target_file}` format..." ).format(target_file=target_file) ```` The string is first constructed using f-strings (which safely inject LLM output), but then `.format()` is applied to the entire string. If `code`, `error_msg`, or other inserted content contains `{}` (which is very common in Python code), `.format()` interprets them as placeholders and raises `KeyError`. ## Expected Behavior The repair loop should not crash when LLM-generated code contains curly b...
Python
View on GitHub ↗
Related Content