O3-mini does not format text in API

o3-mini does not format text using the API. Formulas and code come without formatting in the form of text and it is impossible to work with it.

1 Like

I mean, I expect latex for formulas and ``` for code.

Hi @rus1243mor and welcome to the community!

Have you tried specifying that you would like code formatting in your prompt? According to the docs:

…include the string Formatting re-enabled on the first line of your developer message.

1 Like

can you please tell me if this code is correct or better in another way?

‘messages’ => [
[
“role” => “system”,
“content” => “Answer in markdown, latex, etc. format. Use headings (#, *, `, ``, ```, $, etc.), frame code blocks with quotation marks, etc., where necessary.”
],
[
“role” => “user”,
“content” => $prompt
],
],

1 Like

As the link states, just add “Formatting re-enabled” as the very first thing in your prompt. And then follow that up with the rest of your prompt.

The solution is to add the phrase “Formatting re-enabled” before the query for Models (o1 and o3):

$history[] = [
    'role' => 'user',
    // 'content' => $prompt_query, // Do not use this
    'content' => "Formatting re-enabled " . $prompt_query,
];

Are you sure? Maybe:

'messages' => [
                        [
                            "role" => "system", // developer ???
                            "content" => "Formatting re-enabled"
                        ],
                        [
                            "role" => "user",
                            "content" => $prompt
                        ],
                    ],

Yes, in the developer role. Here is a quick example I just tried out:

curl "https://api.openai.com/v1/chat/completions" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $OPENAI_API_KEY" \
    -d '{
        "model": "o3-mini-2025-01-31",
        "messages": [
            {
                "role": "developer",
                "content": "Formatting re-enabled"
            },
            {
                "role": "user",
                "content": "Output Python code that sorts an array of integers."
            }
        ]
    }'

On the output I get:

```python
def main():
  ....

Still, this instruction is not enough for formulas, for example. I expanded it a bit.:

“Formatting re-enabled. Answer in latex if it is a formula, in markdown if it is a code: #, *, backticks, $, etc. Use headings, frame code blocks with quotation marks, etc., where necessary.”

1 Like

suuure
The code you mentioned is not working. My code is working fine. They also mentioned this sentence in the documentation as the very first thing in your prompt.

also this not working for me

"messages": [
            {
                "role": "developer",
                "content": "Formatting re-enabled"
            },
            {
                "role": "user",
                "content": "Output Python code that sorts an array of integers."
            }
        ]

Also, I couldn’t find any documentation mentioning the “role”: “developer”. I don’t believe there is a role named “developer”.

Great! Did it work ok for you with your expanded prompt for latex?

Yes, latex formulas are unformatted, as I wanted.

1 Like