Skip to content

Invalid parameter: messages with role 'tool' must be a response to a preceeding message with 'tool_calls' . #8419

Answered by moonbox3
msajjadariqt asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @msajjadariqt, the error in your subject "messages with role tool must be a response to a preceding message with tool_calls" occurs because the chat history seems to be misconfigured. When dealing with tool calls, and the model, the chat history needs to have the messages in the proper order (with the proper roles) otherwise it throws this error.

For example, with function calling enabled: if a user asks the model a question: What is 10101+1001? the model returns a finish_reason=tool_calls, and then it expects the next message to contain the tool_calls response(s) with the role='tool'. You can see this represented in the screenshot (you'll want to click on it so you can zoom in).

Can …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@msajjadariqt
Comment options

Answer selected by sophialagerkranspandey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants