Im using openai api and including a numerical list in the output format. How come the…
- User
Im using openai api and including a numerical list in the output format. How come the numbers are getting erased? It works in the playground, but not from my script.
- Assistant
I’ve seen this happen before — you’re not doing anything wrong with the API itself, but there are a couple of common reasons why numbered lists disappear in the output when you switch from the Playground to your own script:
Post-processing / stripping in your code
Are you doing something like .strip(), .split(), or textwrap.dedent() on the response?
Some libraries (like Markdown renderers, JSON parsers, or templating code) will remove leading digits + periods if they think it’s a Markdown ordered list.
How you’re accessing the response
In the Playground, you see message.content as rendered Markdown (so numbers show).
- User
I use this:
res.output[0].content[0].text
- Assistant
Got it — that explains it. The structure of the response depends on which API you’re calling and which client version you’re using.
In the Playground, you’re almost certainly using the new Responses API (unified, works with JSON modes, multiple content types).
In your script, if you’re calling .output[0].content[0].text, you’re already digging into the low-level content array. That’s the raw content items (which can be {"type": "text"}, {"type": "image_url"}, etc).
Here’s the catch:
If you only grab content[0].text, you’ll only ever get the first block of text.
If the model’s list comes back split across multiple blocks (e.g. one number per block), then you’ll lose the later numbers.
That would make it look like your list numbers are “erased.”
✅ Fix: join all the text blocks together. For example: pythonCopy code# For Responses API res_text = "".join( part.text for part in res.output[0].content if part.type == "text" )
print(res_text)
If you’re using the Chat Completions API (older one), you should instead access: pythonCopy coderes_text = res.choices[0].message["content"]
Would you like me to show you a full minimal example for both the Responses API and the Chat Completions API, so you can check which one your script is actually using?
- User
res_text is an empty string.
Here is my code:
res = client.responses.create( model=model, # "gpt-4.1-2025-04-14" input=[ { "role": "system", "content": [ { "type": "input_text", "text": sys_prompt } ] }, { "role": "user", "content": [ { "type": "input_text", "text": text, } ] }, ], text={ "format": { "type": "text" } }, reasoning={}, tools=[], temperature=0, max_output_tokens=2048, top_p=1, store=True, include=["web_search_call.action.sources"] )
- Assistant
Thanks for showing the snippet — now it’s clear what’s going on. You’re using the new Responses API (client.responses.create). In this API, the model’s reply is not in .output[0].content[0].text directly — that’s why you get empty or truncated text. Instead, you should use the helper property res.output_text, which stitches together all the text segments for you. Example: pythonCopy coderes = client.responses.create( model="gpt-4.1-2025-04-14", input=[ { "role": "system", "content": [{"type": "input_text", "text": sys_prompt}], }, { "role": "user", "content": [{"type": "input_text", "text": text}], }, ], text={"format": {"type": "text"}}, reasoning={}, tools=[], temperature=0, max_output_tokens=2048, top_p=1, store=True, include=["web_search_call.action.sources"], )
print(res.output_text) # <- This gives the full model text output
🔑 Why your numbers “disappeared”:
When you grab res.output[0].content[0].text, you only take the first text block.
Lists often get split into multiple content blocks (each 1., 2., etc. can be separate).
So you weren’t seeing them, even though they were there.
- User
Why isn't the output identical to the one on the playground?
- Assistant
Great question 👌 Here’s why your script’s output doesn’t look identical to what you see in the Playground:
- Different defaults
The Playground automatically calls res.output_text (i.e. it concatenates all the text chunks for you and shows it rendered as Markdown).
Your script is drilling into the raw output[0].content list, which is lower-level. That means:
You only see the first chunk if you use [0].
You don’t see Markdown rendering (so numbered lists look like plain text instead of a rendered list).
- Structured content vs rendered text
The new Responses API is designed to return structured content (content: [{type: "text", text: "..."}]).
Sometimes the model splits output into multiple text blocks (especially with lists, tables, or mixed media).
The Playground stitches them together for display, but your script wasn’t — so it looked like things were missing.
- User
The playground outputs: "זה לא נראה כמו קיבוץ. זה נראה כמו מחנה השמדה." My code outputs: 'זה נראה כמו מחנה השמדה.' for the same prompt and hyperperameters.
- Assistant
Ah, that’s a very different issue — thanks for clarifying with the concrete example. If the content itself is different (not just formatting of lists), then there are a few things at play:
🔍 Why Playground vs script can differ
API surface mismatch
In the Playground, by default you’re using the Responses API in plain text mode.
In your script, you’re forcing: pythonCopy codetext={"format": {"type": "text"}} reasoning={} tools=[] include=["web_search_call.action.sources"]
- User
I got this:
res = client.responses.create( model=model, # "gpt-4.1-2025-04-14" input=[ { "role": "system", "content": [ { "type": "input_text", "text": sys_prompt } ] }, { "role": "user", "content": [ { "type": "input_text", "text": text, } ] }, ], text={ "format": { "type": "text" } }, temperature=0, max_output_tokens=2048, top_p=1, store=True, ) print(res.output_text) זה נראה כמו מחנה השמדה.
- Assistant
Thanks for pasting that — this rules out the “you only grabbed the first block” theory, since you’re already calling res.output_text. That means the real reason your script’s output is shorter than the Playground’s is almost certainly different request configuration between the two.
Why this happens
The Playground doesn’t send text={"format": {"type": "text"}}
That parameter is optional, and when you include it, you’re telling the API to enforce a very strict output schema.
In practice, this can truncate or simplify the output (e.g. only the last sentence).
System prompt differences
The Playground injects some hidden defaults (like safety + formatting instructions).
Your script doesn’t, unless you explicitly include them.
That can cause the model to phrase things differently.
- User
This didn't help. Write an instruction to get the full quote "זה לא נראה כמו קיבוץ" and also include the numbers! I will send you the prompt
- Assistant
Got it 👍 If the model sometimes drops "זה לא נראה כמו קיבוץ" or erases list numbers, you can fix that by being explicit in your system instruction. For example: textCopy code## Output Formatting Instruction Always return the model’s response verbatim without omitting, paraphrasing, or summarizing.
Do not shorten or remove any sentences.
If the text contains the phrase "זה לא נראה כמו קיבוץ", it must appear in full exactly as written.If you output a numbered list, keep the numbers exactly as they are (e.g., "1.", "2.", "3.") and do not change them to bullet points or remove them.
Do not alter or collapse multiple numbers into one block.Return the response as plain text, with all sentences and list numbering preserved exactly.
👉 If you paste me your current prompt, I can weave this instruction into it directly so that you get the full "זה לא נראה כמו קיבוץ" and the numbered lists without the API stripping them. Do you want me to integrate it into your system prompt or the user prompt?
- User
- Assistant
Perfect — thanks for sharing the full prompt. To make sure you always get the complete quote (e.g. "זה לא נראה כמו קיבוץ") and preserve the numbering exactly (1., 2., etc.), you need to tighten the output-format instruction inside your system message. Right now, the model is allowed to “summarize” or “drop” parts. Here’s an updated version of your instruction section (the rest of your definitions/clarifications/examples can stay as-is):
textCopy code### Output Formatting Rules (Strict)
-
Do not shorten, omit, or paraphrase.
-
Always copy the full sentence from the transcript that contains the reference.
-
If the sentence is fragmented, include the full fragment exactly as it appears, even if it looks incomplete.
-
If the text contains "זה לא נראה כמו קיבוץ", it must appear in full exactly as written.
-
If there are mentions, list them .
-
- User
this is repetitive with the current:
- If there are mentions, list them numerically (starting with "1."), one per line, even if they appear together in the same block of text.
- Assistant
You’re right — your current prompt already tells the model to use numbers, so we don’t want to confuse it with redundant rules. The issue is less about “numbers” and more about verbatim extraction (don’t drop or paraphrase text). Here’s a minimal, non-repetitive addition you can append at the end of your Instructions section: textCopy code- Always reproduce the full sentence exactly as it appears in the transcript, without shortening, omitting, or paraphrasing.
- This includes preserving phrases like "זה לא נראה כמו קיבוץ" exactly as written.
That way:
You don’t repeat the numbering rule.
You give a clear, single instruction about keeping the full quote verbatim.
Do you want me to merge this into your prompt for you so it flows smoothly, or would you rather keep it as a separate block at the end?
- User
- Assistant
Yes — this is much better 👍. By pulling the numbering + verbatim requirements into a dedicated “Output Formatting Rules (Strict)” block, you:
Avoid repeating the earlier instruction,
Make the “don’t shorten / don’t paraphrase” rule highly visible,
Keep the structure clean: Instructions → Output Formatting Rules → Clarifications → Guidelines → Steps → Examples.
This way the model has a very clear contract:
Detection is governed by your “Clarifications” section.
Extraction is governed by “Extraction Guidelines”.
Formatting & completeness is governed by “Output Formatting Rules”.
That separation reduces the chance the model “decides” it can omit part of a quote like "זה לא נראה כמו קיבוץ" or drop list numbers. If you want to make it even sharper (without adding repetition), you could add one last bullet under Output Formatting Rules: textCopy code- If a Holocaust reference appears, the entire phrase must be reproduced verbatim, even if it seems redundant or fragmentary.
This way, the model has zero wiggle room to skip "זה לא נראה כמו קיבוץ". Would you like me to streamline the Examples section too, so the positive/negative examples directly reinforce the formatting rules (i.e., each positive example shows numbers and full sentences)?
- User
It is too long! shorten the prompt a bit. When I ran just on some of the promt I got the numbers. (though I didn't get "זה לא נראה כמו קיבוץ") I don't want to state that explicity. it should be obious.
- Assistant
Got it — we can make the prompt much shorter and still preserve the key points: detect Holocaust references in October 7th testimonies, extract full sentences, and keep numbering intact, without explicitly calling out any particular phrase. Here's a concise version:
textCopy codeYou are a Jewish History researcher. Below is part of a testimony transcript told in Hebrew by a survivor of the October 7th attack on southern Israel.
Instructions:
- Identify explicit references to the Holocaust in the testimony related to October 7th events, including comparisons, metaphors, or symbolic references.