Skip to content

tools_reasoning.rs panics if the model answers with just a tool call without reasoning #992

@fhars

Description

@fhars
cargo run --release --example tools_reasoning -- --continous hf-model mistralai/Ministral-3-3B-Reasoning-2512-GGUF Ministral-3-3B-Reasoning-2512-Q4_K_M.gguf

....

thread 'main' (142586) panicked at llama-cpp-2/../examples/tools_reasoning.rs:459:18:
Failed to apply follow-up chat template: FfiError(-3)

The reason is a "reasoning_content":null in the conversation history which causes an exception from

wrapper_oai.cpp:378:        inputs.messages = common_chat_msgs_parse_oaicompat(json::parse(params->messages));

This might be one solution:

diff --git a/examples/tools_reasoning.rs b/examples/tools_reasoning.rs
index c18a28f..92d2e30 100644
--- a/examples/tools_reasoning.rs
+++ b/examples/tools_reasoning.rs
@@ -308,7 +308,7 @@ fn assistant_tool_call_message(parsed_message: &serde_json::Value) -> serde_json
         "reasoning_content": parsed_message
             .get("reasoning_content")
             .cloned()
-            .unwrap_or(serde_json::Value::Null),
+            .unwrap_or(json!("")),
         "tool_calls": tool_calls,
     })
 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions