Skip to content

Parse XML tool-use repl blocks in find_code_blocks - #189

Open
MohammadHijjawi97 wants to merge 1 commit into
alexzhang13:mainfrom
MohammadHijjawi97:fix-parse-xml-repl-tool-calls
Open

MohammadHijjawi97 wants to merge 1 commit into
alexzhang13:mainfrom
MohammadHijjawi97:fix-parse-xml-repl-tool-calls

Conversation

@MohammadHijjawi97

Copy link
Copy Markdown

Fixes #179

Claude models often emit their native XML tool-use syntax instead of repl fences:

<function_calls>
<invoke name="repl">
<parameter name="code">
print(len(context))
</parameter>
</invoke>
</function_calls>

find_code_blocks() only matched fences, so none of that code was executed and the model went on to hallucinate the outputs.

Changes:

  • find_code_blocks() now falls back to parsing <invoke name="repl"><parameter name="code">...</parameter></invoke> blocks when no repl fence is present, which is the fix proposed in the issue. Fenced parsing and ordering are unchanged, and fences take precedence when both appear.
  • Fixed the docstring: the function returns an empty list, not None.
  • Added unit tests in tests/test_parsing.py for single and multiple XML blocks, ignoring non-repl invokes, and fence precedence.

Tests: pytest tests/test_parsing.py tests/test_imports.py (55 passed, 3 skipped); ruff check / ruff format --check clean. The XML tests fail without the change.

Note: #175 adds a None guard in the same function, so whichever lands second may need a trivial rebase.

Claude models often emit native XML tool-use syntax
(<invoke name="repl"><parameter name="code">...</parameter></invoke>)
instead of ```repl``` fences, so none of their code was executed.
Fall back to parsing those blocks when no fenced block is present.

Fixes alexzhang13#179

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Claude models emit XML tool-use syntax instead of repl fences — code silently never executes, model hallucinates results

1 participant