Describe the Bug
Until yesterday, structured JSON output worked when using sonar-reasoning-pro.
Here is a minimal query example:
import json
import requests
import pydantic
class MyBaseModel(pydantic.BaseModel):
model_config = pydantic.ConfigDict(extra="forbid")
class GenericAnswerFormat(pydantic.BaseModel):
result: str
url = "https://api.perplexity.ai/chat/completions"
headers = {
"Authorization": f"Bearer {yourkeyhere}",
"Content-Type": "application/json",
}
data = {
"model": "sonar-reasoning-pro",
"messages": [
{
"role": "system",
"content": "You are an AI assistant that provides structured JSON output.",
},
{
"role": "user",
"content": "Give me information about the Eiffel Tower in Paris.",
},
],
"response_format": {
"type": "json_schema",
"json_schema": {"schema": GenericAnswerFormat.model_json_schema()},
},
}
print(json.dumps(data, indent=2))
response = requests.post(url, headers=headers, json=data)
if response.status_code == 200:
print(response.json())
else:
print(f"Error: {response.status_code}, {response.text}")
Expected Behavior
Get a result.
Actual Behavior
Error: 400, {“error”:{“message”:“Structured output schema error. Please refer to
Overview - Perplexity for more information.”,“type”:“invalid_parameter”,“code”:400}}`
If I change the model to “sonar-pro” above, the query works as expected.
Steps to Reproduce
See above.