huggingface / huggingface/smolagents

Repeatedly getting "Error in code parsing: Your code snippet is invalid"

Open
#201 38 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
29.3k
Forks
3k
Avg merge
17m
Merged PRs (30d)
2

Description

I repeatedly get this error when using the Codeagent:

```Error in code parsing:
The code blob is invalid, because the regex pattern ```(?:py|python)?\n(.*?)\n``` was not found in code_blob ...
```

I have tried to emphasize proper code block formatting in the agent.run() argument, to no avail.

The error occurs while using GPT-4o and Sonnet 3.5.

How can I fix this or at least improve realiability?

Thanks for any help in this regard!

Contributor guide

Open the contributing guide

Research direction

No source file or test is named in the report. Start by reproducing the failure with agent.run() using GPT-4o or Sonnet 3.5, then trace where the reported code-block regex is applied. Done means reliably handling the returned code or providing a clear, actionable parsing failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
ai
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.