Skip to content

Commit c4ff3e4

Browse files
ochafikclaude
andcommitted
generic: allow optional content field in tool call response
Upstream now defaults message content to empty string instead of null, which adds "content": "" to JSON output after tool_calls. Update both the PEG grammar and test expectation to handle this. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent d6224b6 commit c4ff3e4

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

common/chat-parsers/generic.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,18 @@ common_chat_params common_chat_params_init_generic_peg(const common_chat_templat
4040
+ any_tool_call + p.repeat(p.space() + p.literal(",") + p.space() << any_tool_call, 0, inputs.parallel_tool_calls ? -1 : 0)
4141
+ p.space() + p.literal("]");
4242

43+
// Allow optional "content": "" field after tool_calls (upstream now adds this by default)
44+
auto optional_content_field = p.optional(
45+
p.literal(",") << "\"content\"" << ":" << "\"\""
46+
);
47+
4348
auto tool_calls = p.trigger_rule("tool-call-root",
4449
p.space() // Allow optional leading whitespace
4550
+ p.literal("{")
4651
<< "\"tool_calls\""
4752
<< ":"
4853
<< tool_calls_parser
54+
<< optional_content_field
4955
<< "}");
5056

5157
if (inputs.tool_choice == COMMON_CHAT_TOOL_CHOICE_REQUIRED) {

tests/chat-parsers/test-generic.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ void test_generic_parser(chat_parser_impl impl)
9393
" },\n"
9494
" \"id\": \"123456789\"\n"
9595
" }\n"
96-
" ]\n"
96+
" ],\n"
97+
" \"content\": \"\"\n"
9798
"}");
9899
}
99100

0 commit comments

Comments
 (0)