Hello,
I have a question about Tools in the Responses API. How can I ensure that the text given to a Tool is used without summarization? For example, if there’s a Tool that returns a URL, and this URL is long, the Responses API summarizes it. Since it’s a URL, summarization is problematic. I’ve attached a sample below.
Thanks,
You might consider giving back a JSON string so that it is very clear what is the URL. And of course in your prompt (or in the tool function description) you can mention that the URL might be very long but cannot be truncated.
I just tried it in playground (using 4.1) and this prompt ‘Find the book “Alone” return Markdown with the title of the book and the embedded link to the book.’ And I pasted exactly you string and added ‘F0’ at the end so I could see that it took the whole string. The response was as expected:
Here is the information I found:
**Book Title:** Book of ABC-XYZ
**Abstract:** (No detailed abstract provided.)
**PDF Link:** You can access the full book as a PDF here: [Book of ABC-XYZ PDF](https://abc.com/xyz.pdf?abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&...)
If you need a summary, specific chapters, or have any questions about the content, let me know!
I tested it here and couldn’t replicate your issue using the placeholder you provided.
Could you try this python script, replacing your own url to see if the problem persists?
I only added a few system instructions and provided the return answer as a json.
Python example
from openai import OpenAI
client = OpenAI()
select_model="gpt-4.1"
tools = [{
"type": "function",
"name": "get_book_information",
"description": "Search for a e-book information like description and url to access.",
"parameters": {
"type": "object",
"properties": {
"name": {"type": "string"},
},
"required": ["name"],
"additionalProperties": False
},
"strict": True
}]
input_messages = [{"role": "user", "content": "I need details on the book: Getting started with XYZ, and a link to download it."}]
response = client.responses.create(
model=select_model,
input=input_messages,
instructions="Make sure that URLs always remain unchanged.",
tools=tools,
)
tool_call = response.output[0]
args = json.loads(tool_call.arguments)
result = {
"description": "a book about xyz",
"url":"https://abc.com/xyz.pdf?abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz#EOF"
}
# append result message
input_messages = [{
"type": "function_call_output",
"call_id": tool_call.call_id,
"output": str(result)
}]
response_2 = client.responses.create(
model=select_model,
previous_response_id=response.id,
input=input_messages,
tools=tools,
)
print(response_2.output_text)
Output:
Here are the details for the book you requested:
Title: Getting Started with XYZ
Description: A book about xyz.
Thank you.
When I ran the Python script you provided several times, it indeed resulted in the URL being summarized as follows.
Here are the details for the book "Getting started with XYZ":
- Description: A book about xyz.
You can download the book using this link: Download Getting started with XYZ (https://abc.com/xyz.pdf?abcdefghijklmnopqrstuvwxyz=abcdefghijklmnopqrstuvwxyz&...#EOF)
Nice. Also considering you always expect an url, you could simply take the json and replace the string directly before returning the final result, preventing the model from unintentionally modifying it further.
Whether using JSON format is suitable for the app under development requires consideration. However, it’s helpful that the options to consider have increased. Thanks.
The app I’m developing is based on AI chat. Since I want natural interactions in normal use, I don’t want to do JSON-like processing. Is there a way to receive only the output from when search tools are used in JSON format?
You can re-run the first code I sent you (text) with the extra parameters. I only used json to be able to check if it matches. I added truncation, temperature, top_p and max_token parameters.
Even if I use JSON format, it seems that URLs still get ‘summarized’ when the overall amount of information increases. That’s disappointing. But thank you.