Filter tool call data with tool message

Hello! I’m trying to use tools to reply to a given user question. The tool calls a function that gathers raw information from an API and then has to be refined by the model. I thought this could be done by replying to the model, after the tool has been called, with the role == “tool” by passing the raw data directly to the model, but the user question is not answered with the usual quality that the model would have.
Additionally to the raw information, the content of my “tool” role message has the following sentence:

‘Filter the results based on the user's inquiry: “{query}” and return them in the same JSON format.\n’

where “query” is the original user question.

I would like to know how to correctly do this, it is right to use the “tool” role message or else anybody has done something similar.

Thank you very much!

The function description should give a good idea of the purpose of the tool and what it returns. That main description alone should be enough for the AI to understand what to do with extra data from the tool, even if it is excessive or code-like.

Then messages should be added after the user input:

user: what color is a flurb in April?
assistant->dictionary: language:“unknown”, query: “flurb?”
tool (name): “In the spring, the flurbs run free in the Among, with the doopo of their coat turning a bright and colorful rebeccapurple…”

The assistant and tool both need the emitted id, so their pairing is forced on you. You don’t need to amend more to the tool return than the knowledge, as the AI can understand what is returned, what the user asked, what it queried, and what should be paraphrased based on its understanding of the terseness of the function return from specs.