Structured output is not structured

:bug: Describe the Bug

Structured output doesnt work stable - with one code and one environment it builds sometimes structured output and sometimes not. It works so even with structured code example from documentation.

:white_check_mark: Expected Behavior

Structured output works always.

:cross_mark: Actual Behavior

Structured output works unstable.

:counterclockwise_arrows_button: Steps to Reproduce

Run code from example multiple times (https://docs.perplexity.ai/guides/structured-outputs):

import requests
from pydantic import BaseModel

class AnswerFormat(BaseModel):
    first_name: str
    last_name: str
    year_of_birth: int
    num_seasons_in_nba: int

url = "https://api.perplexity.ai/chat/completions"
headers = {"Authorization": "Bearer YOUR_API_KEY"}
payload = {
    "model": "sonar",
    "messages": [
        {"role": "system", "content": "Be precise and concise."},
        {"role": "user", "content": (
            "Tell me about Michael Jordan. "
            "Please output a JSON object containing the following fields: "
            "first_name, last_name, year_of_birth, num_seasons_in_nba. "
        )},
    ],
    "response_format": {
		    "type": "json_schema",
        "json_schema": {"schema": AnswerFormat.model_json_schema()},
    },
}
response = requests.post(url, headers=headers, json=payload).json()
print(response["choices"][0]["message"]["content"])

:pushpin: API Request & Response (if applicable)

:globe_showing_europe_africa: Environment

  • API Version: Current (model - sonar)
  • Pydantic version (used for BaseModel): 2.11.7
  • Operating System: Linux, Windows

:paperclip: Logs or Screenshots (if applicable)

Several runs of the code from the example:

PS C:\> & ... test.py
{ "first_name": "Michael", "last_name": "Jordan", "year_of_birth": 1963, "num_seasons_in_nba": 15 }
PS C:\> & ... test.py
{"first_name":"Michael","last_name":"Jordan","year_of_birth":1963,"num_seasons_in_nba":15}
PS C:\> & ... test.py
```json
{
  "first_name": "Michael",
  "last_name": "Jordan",
  "year_of_birth": 1963,
  "num_seasons_in_nba": 15
}
\```
Michael Jordan was born in 1963 and played 15 seasons in the NBA between 1984 and 2003[1][3][5].
PS C:\> 

:memo: Additional Context

I’ve been using Structured Output in Perplexity for a long time, it stopped working recently

4 Likes

I am also encountering this issue

Same issue is happening for me today, now that i wanted to test my code before prod. WTF perplexity

Same. Used Perplexity structured output in production app and it now returns plaintext response more often than not. Seems to be completely ignoring the json schema provided to it. It worked well before this week.

Hey everyone! We apologize for the inconvenience. This issue should now be resolved. If anyone is still experiencing problems with structured outputs, please let us know with code samples and timestamps!