Skip to content

[BUG] code block parsing fail due to triple backticks #1219

Open
@joejoe2

Description

@joejoe2

Describe the bug
The code running will fail if LLM put triple backtisk ``` in Thoughts:
May related to #201

Code to reproduce the error

from smolagents import parse_code_blobs, fix_final_answer_code
code_action = fix_final_answer_code(parse_code_blobs("""
Thought:
xxxxxxxxxxxxxxx
```
invalid code
```

Code:
```
print("valid code")
```"""))
assert "invalid code" not in code_action

Error logs (if any)
None

Expected behavior
should be print("valid code")

Packages version:
smolagents==1.13.0

Additional context
If code block caontins nested backtisk, it will also fail.
ex.

final_anwser("""
   ``` nested ```
""")

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions