You don’t discuss if you’re showing us lines of code, or the printed contents of JSON.
Let’s talk in Python code, at a REPL shell or notebook, with the necessary escaping like JSON to use solely double-quotes in the code.
- put the string to be sent as tool return into a variable
the_text = "{\"message\": {\"ticker\": \"NVDA\", \"current_price\": 179.27, \"previous_close\": 175.51, \"price_change\": 3.76, \"price_change_percent\": 2.14, \"volume\": 166546229, \"high_90d\": 179.89, \"low_90d\": 104.07, \"date\": \"2025-07-30\"}}"
You can send any ol’ text that the AI can understand.
If you’re unsure that the string is actually clean and JSON-looking for AI understanding:
>>> print(the_text)
{"message": {"ticker": "NVDA", "current_price": 179.27, "previous_close": 175.51, "price_change": 3.76, "price_change_percent": 2.14, "volume": 166546229, "high_90d": 179.89, "low_90d": 104.07, "date": "2025-07-30"}}
(note that yours might have had an extra curly at the end)
(this text really doesn’t need to be enclosed in “message” or any curly-braces. You might process an API’s string into JSON, into just the value of the message.)
- put the variable into the construction of an API parameter object:
>>> the_content= [
... {
... "text": the_text,
... "type": "text"
... }
... ]
- create a message item to add to the chat:
>>> the_tool_return_message = {
... "role":"tool",
... "content":the_content,
... "tool_call_id": "12345"
... }
Add this to your python list of dictionary messages (input).
Then - using the printed text of the_text when a prompted AI uses my function:
The JSON API call body that is formed, responding to function call, raw and in full:
{"messages":[{"role":"system","content":[{"type":"text","text":"You are a helpful AI language model."}]},{"role":"user","content":[{"type":"text","text":"Is nVidia stock still trending up?"}]},{"role":"assistant","content":[],"tool_calls":[{"id":"call_aykEepIIlzXEDnZDzkT0IMtR","type":"function","function":{"name":"get_stock_ticker","arguments":"{\"ticker\":\"nVidia\"}"}}]},{"role":"tool","content":[{"type":"text","text":"{\"message\": {\"ticker\": \"NVDA\", \"current_price\": 179.27, \"previous_close\": 175.51, \"price_change\": 3.76, \"price_change_percent\": 2.14, \"volume\": 166546229, \"high_90d\": 179.89, \"low_90d\": 104.07, \"date\": \"2025-07-30\"}}}"}],"tool_call_id":"call_aykEepIIlzXEDnZDzkT0IMtR"}],"temperature":1,"max_completion_tokens":2048,"top_p":1,"frequency_penalty":0,"presence_penalty":0,"model":"gpt-4.1","response_format":{"type":"text"},"tools":[{"type":"function","function":{"name":"get_stock_ticker","description":"Returns the stock ticker symbol based on provided symbol or company name if symbol is unmatched","parameters":{"type":"object","properties":{"ticker":{"type":"string","description":"Stock ticker symbol or company name to search for"}},"required":["ticker"],"additionalProperties":false},"strict":true}}],"parallel_tool_calls":true,"stream":true,"stream_options":{"include_usage":true}}