I use sonar-deep-research API with promt and json output format. But the API output is not consistent. One output matches the format described (generates the required number of paragraphs and graphs specified in the prompt sometimes), while the other does not and looks quite short. It feels like the answer is incomplete, like there aren’t enough tokens to withdraw or something like that. Has anyone encountered a similar problem and can suggest how to fix it, please?
My config
const deepResearch = {
id: 'sonar-deep-research',
prompt: `
You are a financial AI research assistant. Analyze the user's query and provide comprehensive insights with data visualization.
Output ONLY valid JSON following this structure:
{
"answers": [
{ "paragraph": "Brief markdown analysis..." },
{
"chartBar": {
"title": "Chart title",
"description": "Short description",
"label": "Y-axis label",
"data": [
{ "axis": "Category 1", "value": 123.45 },
{ "axis": "Category 2", "value": 678.90 }
]
}
},
{
"chartLine": {
"title": "Chart title",
"description": "Short description",
"label": "Y-axis label",
"data": [
{ "sector": "Item 1", "value": 100.5 },
{ "sector": "Item 2", "value": 200.7 }
]
}
},
{ "paragraph": "Additional insights..." },
{ "sources": [{ "name": "Source Name", "link": "https://example.com" }] }
]
}
Requirements:
- Must include at least 2 "chartBar" and one "chartLine" with relevant financial data
- Include 5-10 "paragraph" blocks with concise markdown analysis (3-4 sentences each)
- End with exactly one "sources" array containing all referenced sources
- If no external sources exist, use: {"sources":[{"name":"Internal Analysis","link":"https://perplexity.ai"}]}
- All chart values must be numeric
- Maximum 10 data points per chart
- Be concise, factual, and avoid repetition
- Output only the JSON object, no additional text
`,
schema: {
type: 'object',
properties: {
answers: {
type: 'array',
items: {
oneOf: [
{
type: 'object',
properties: {
paragraph: { type: 'string' },
},
required: ['paragraph'],
additionalProperties: false,
},
{
type: 'object',
properties: {
chartBar: {
type: 'object',
properties: {
title: { type: 'string' },
description: { type: 'string' },
label: { type: 'string' },
data: {
type: 'array',
maxItems: 10,
items: {
type: 'object',
properties: {
axis: { type: 'string' },
value: { type: 'number' },
},
required: ['axis', 'value'],
additionalProperties: false,
},
},
},
required: ['title', 'description', 'label', 'data'],
additionalProperties: false,
},
},
required: ['chartBar'],
additionalProperties: false,
},
{
type: 'object',
properties: {
chartLine: {
type: 'object',
properties: {
title: { type: 'string' },
description: { type: 'string' },
label: { type: 'string' },
data: {
type: 'array',
maxItems: 10,
items: {
type: 'object',
properties: {
sector: { type: 'string' },
value: { type: 'number' },
},
required: ['sector', 'value'],
additionalProperties: false,
},
},
},
required: ['title', 'description', 'label', 'data'],
additionalProperties: false,
},
},
required: ['chartLine'],
additionalProperties: false,
},
{
type: 'object',
properties: {
sources: {
type: 'array',
minItems: 1,
maxItems: 20,
items: {
type: 'object',
properties: {
name: { type: 'string' },
link: { type: 'string', format: 'uri' },
},
required: ['name', 'link'],
additionalProperties: false,
},
},
},
required: ['sources'],
additionalProperties: false,
},
],
},
allOf: [
{
contains: { type: 'object', required: ['chartBar'] },
minContains: 1,
},
{
contains: { type: 'object', required: ['chartLine'] },
minContains: 1,
},
{
contains: { type: 'object', required: ['sources'] },
minContains: 1,
maxContains: 1,
},
],
},
},
required: ['answers'],
additionalProperties: false,
},
},
I use
temperature: 0.7,
reasoning_effort: ‘medium’,
search_mode: ‘web‘