Repository navigation
How to parse structured data from an AI's response? (text + tool call XML) #783
Unanswered
mddd (mdddj)
asked this question in
Q&A
Replies: 1 comment
|
It's better to use the native tool capability rather than asking the model to generate tool messages using xml. It can be done by passing a tool registry to an agent or by passing tools parameters to the If you'll provide a code snippet how you call the model, I can help you update it to use the native tool calls. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I'm building a system where an AI model can invoke tools by generating a specific text format in its response. I need to reliably parse this tool-call information, which is often mixed with natural language.
Here's a concrete example of the interaction:
User Input:
Help me generate a test file.
AI's Response:
So, the main question is: what's the best strategy to process these kinds of mixed responses and parse them into my structured data classes (TextContent or ToolUse)?
Additionally, I've noticed that some less advanced models tend to wrap the tool-call XML in a Markdown code block, like this:
Okay, I will call the file writing tool.
This is bad (GoogleModels.Gemini2_0Flash)

This is good (GoogleModels.Gemini2_5Pro)

To provide more context, here are the Kotlin data classes I am using to represent the assistant's message. My goal is to parse the AI's text response into one of these structures.
All reactions