Why is GPT API giving me a response with lots of spaces and new lines?

At first, I’m sorry that I cannot share the prompt messages I used for the input.

For some prompts, the contents of response only consists of lot’s of spaces and new lines. It doesn’t happens everytime, but sometimes without control.

Q1. Why is this happens
Q2. How to prevent from this situation?

2 Likes

You probably need to share more details of your prompt with us to reproduce the issue. Also try to adjust temperature and system prompt.

When you send blank prompts, the LLM doesn’t have anything to “latch onto” to find what might come next, so it goes a bit nuts.

I would make sure your prompt always includes something. If it’s empty or just newlines, just don’t send it and show a canned message to user maybe?

i have same question too, here is my prompt im make sure my prompt includes my question and agent step logs when i used function call

I’m trying to build a Python script to feed information to chatGPT using the following script
from openai import OpenAI

Blockquote
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model=“gpt-3.5-turbo-0125”,
response_format={ “type”: “json_object” },
messages=[{“role”: “system”, “content”: “You are a young and intelligent software engineer assigned to the task to identify ambiguities in the system requirements JSON”},
{“role”: “user”, “content”: “Identify ambiguities in the following software requirement”},
{“role”: “user”, “content”: “Once borrower clicks on the Payment Request link sent to their email address we need to retrieve the Payment Request Information and return it to the borrower.”}],
temperature=1,
top_p=1
)
print(response)

I’m obtaining

Blockquote
ChatCompletion(id=‘chatcmpl-8u5VtF1zBTMl55pADtV6R0tCmm2eC’, choices=[Choice(finish_reason=‘stop’, index=0, logprobs=None, message=ChatCompletionMessage(content=‘\n \n\n \n \n\n \n \n\n \n \n\n \n \n\n \n \n\n \n \n\n \n \n\n \n \n \n\n \n \n\n \n\n \n\n \n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n’, role=‘assistant’, function_call=None, tool_calls=None))], created=1708378253, model=‘gpt-3.5-turbo-0125’, object=‘chat.completion’, system_fingerprint=‘fp_69829325d0’, usage=CompletionUsage(completion_tokens=278, prompt_tokens=73, total_tokens=351))

Not sure how to address this, using the same argument with the Web chat interface provides a reasonable answer.

Thanks!, Pedro.

Blockquote

1 Like

@pwdro.colla, did you find a solution for this problem?

We are experiencing the same problem - 5-10 times a day this one specific prompt (running on gpt-4-turbo-preview) will return a table header, then 20-70kB of whitespace. Already deployed code to check for that scenario and rerun (most of the time it is fine on rerun)

Sometimes at the end will be some repeating mandarin characters too!

Try adding the assistant’s response in between your user messages.

This gives me a sane output:

usemodel="gpt-3.5-turbo-0125"
client = OpenAI()
response = client.chat.completions.create(
model=usemodel,
response_format={ "type": "json_object" },
messages=[{"role": "system", "content": "You are a young and intelligent software engineer assigned to the task to identify ambiguities in the system requirements and output it in JSON"},
{"role": "user", "content": "Identify ambiguities in the following software requirement"},
{"role": "assistant", "content": "To help you identify ambiguities, I'll need to see the specific software requirement you're referring to. Could you please provide the requirement text?"},
{"role": "user", "content": "Once borrower clicks on the Payment Request link sent to their email address we need to retrieve the Payment Request Information and return it to the borrower."}],
temperature=1,
top_p=1
)
print(response)
1 Like

Try this you will get this \n\n kind of response

[{‘role’: ‘system’, ‘content’: ‘I want you to create a simple AWS Athena queries query based on my query and remember you have to always create sql query to fetch correct data from database and always limit data length to 10000 rows and whenever year is provided in the table fetch it in query ,Also make accurate queries using your memory\r\n \r\n### Rules to Follow:\r\n \r\n0. Do not use Distinct anytime and Avoid Over-Filtering with NULL Checks:\r\n1 do not do calculation like percentages,total or any others even if asked just provide me the data I will do calculations by my own\r\n2 Ensure you do not use COUNT(*) when calculating percentages, as it includes all rows instead of just the relevant subset, leading to inaccurate results.\r\n3 Always try to accumulate all the years for same data and try to get year if present in data unless users specify \r\n4 Whenever using a WHERE condition, always use lower() for string-type values to ensure case-insensitive matching.\r\n5 Always use aggregate queries with the GROUP BY clause whenever aggregating values. \r\n6 When creating aggregate queries with a GROUP BY clause, ensure that any non-aggregate fields present in the SELECT or ORDER BY clauses are also included in the GROUP BY clause to avoid aggregation errors.\r\n7 When using an ORDER BY clause in a query that contains aggregation (SUM, COUNT, etc.), ensure that any fields used for ordering are also included in the GROUP BY clause if they are not part of an aggregate function\r\n8 Do not include any column in the GROUP BY clause if it is not available in the SELECT or ORDER BY clauses.\r\n9 Try to get column important columns along which could be useful to understand data\r\n10 Whenever using a WHERE condition, always use lower() for string-type values to ensure case-insensitive matching.\r\n11 Always include the years. never leave out “fiscal_year” [string]\r\n12 Always Include year, fiscal_year, and term columns in SELECT only when available in the table information. If another date column is available, bring that column instead.\r\n13. use joins when more than two tables are given to you\r\n \r\n \r\nUSE BELOW TABLE\n\n"table_name is 'field_of_study' and columns are 'country' [string], 'business_mgmt' [double], 'education' [double], 'engineering' [double], 'fine_applied_arts' [double], 'health_professions' [double], 'humanities' [double], 'intensive_english' [double], 'math_computer_science' [double], 'physical_life_sciences' [double], 'social_sciences' [double], 'other_fields_of_study' [double], 'undeclared' [double], 'countrycode' [string], 'continent' [string], 'continentcode' [string], 'sub_continent' [string], 'sub_continentcode' [string], 'fiscal_year' [string].'\n'Instruction for this table':\n'1. this table includes data by percentages NOT scores of students from the top 25 leading countries, keep as percentages using 'fiscal_year', \n2. 'business_mgmt' or 'education' or 'engineering' or 'fine_applied_arts' or 'health_professions' or 'humanities' or 'intensive_english' or 'math_computer_science' or 'physical_life_sciences' or 'social_sciences' or 'other_fields_of_study' or 'undeclared' are percentages."\n\nImportant \n\n Always provide me Output in json format with key name 'query'’}, {‘role’: ‘user’, ‘content’: ‘what are some recruitment strategy for Vietnam’}, {‘role’: ‘assistant’, ‘content’: ‘sql query’}, {‘role’: ‘user’, ‘content’: ‘what are some recruitment strategy for Vietnam’}]

The solution is use this format in content use ‘type’ and ‘text’

"content": [
        {
          "type": "text",
          "text": "what are some recruitment strategy for Vietnam"
        }
      ]