Sonar AP returning empty results or malformated |

:bug: Describe the Bug

We request to deliver latest insights for specific persons online. and Randomly we get the below response. after triggering it multiple times it works but why after multiple times, and the costs related to that.

:white_check_mark: Expected Behavior

I send thw request and get the response at once, no empty lines or corrupted responses

:cross_mark: Actual Behavior

What actually happened.

:counterclockwise_arrows_button: Steps to Reproduce

  1. Call the API with the following request:

2025-09-05 13:46:35,483 - INFO - Assistant config is loaded…

2025-09-05 13:46:35,483 - INFO - Assistant config: {‘model’: ‘sonar’, ‘temperature’: 0.5, ‘max_tokens’: 2000, ‘stream’: False}

2025-09-05 13:46:35,483 - INFO - Assistant SYS Instruction is loaded…

2025-09-05 13:46:35,483 - INFO - Assistant SYS Instruction: You are an expert research and personalization agent. Use the following information to find unique, meaningful details about this person and/or their company to help craft a highly personalized email. Focus on something very specific to the person first, then their role, then the company. If nothing unique is found, use the most relevant information available.

2025-09-05 13:46:35,483 - INFO - Constructed prompt is created…

2025-09-05 13:46:35,483 - INFO - Constructed prompt:

                Person: Martin Hoerbe

                Position: Global Head Transformation & Operational Excellence

                Country: Germany

                LinkedIn: http://www.linkedin.com/in/martin-hoerbe-5376977

                Company Website: https://alcon.com

                Company LinkedIn: http://www.linkedin.com/company/alcon

                Intent: High Intent to buy solutions (Transcriptions)



                Instructions:



                1\. Preferred Language: Based on the provided country, determine and return the main spoken language (preferred_language) for this prospect. Always include this as a top-level field in your response.



                2\. Persona Assignment: Based on the prospect's job title or position, assign one of the following personas and include it as a top-level field in your response: 'Executives', 'Finance', 'People', 'Sales', 'Product', 'IT'. Choose the most relevant based on the role/position.



                3\. Research and synthesize what makes this person’s role, achievements, or focus areas unique within their organization. Look beyond job titles—identify:

                    - Personal posts or articles, anything relevant to them as a human being

                    - Projects or initiatives they have led or influenced

                    - Strategic or technological transformations they’ve driven

                    - Innovations, systems, frameworks, or methodologies they’ve adopted

                    - Global or cross-functional impact they’ve had

                    - Consider prospect's Country for relevance



                4\. Analyze the company’s recent activities, strategy, and positioning, especially in relation to the person's scope. Industry knowledge & trends: Research current challenges, trends, or regulatory requirements that are relevant to the prospect's role and industry.



                5\. Output Structure:

                    - Your response must be a single valid JSON object with these top-level fields:

                        - fullname

                        - position

                        - country

                        - region: One of: 'EUROPE', 'LATAM', 'APAC', 'NA', 'SEA', 'DACH'.

                        - preferred_language

                        - persona

                        - linkedin_url

                        - company_website

                        - company_linkedin_url

                        - unique_insights: An object (not a list or array) with exactly these three string fields:

                            - "unique_role_contributions"

                            - "strategic_initiatives"

                            - "industry_innovation"

                    Example output:

                        {

                        "fullname": "Maria Vargas",

                        "position": "Director of Operations",

                        "country": "Mexico",

                        "region": "LATAM",

                        "preferred_language": "Spanish",

                        "persona": "Executives",

                        "linkedin_url": " http://www.linkedin.com/in/maria-vargas-b8a534129 ",

                        "company_website": "https://jabil.com",

                        "company_linkedin_url": "http://www.linkedin.com/company/jabil",

                        "unique_insights": {

                            "unique_role_contributions": "Maria led the 2024 digital transformation at Jabil, increasing efficiency by 18% \[1\]. More Insights...",

                            "strategic_initiatives": "She spearheaded the LATAM supply chain optimization project in 2023 \[2\]. More Insights...",

                            "industry_innovation": "Implemented AI-driven quality control systems in 2025 \[3\]. More Insights..."

                        }

                        }

                6\. For each field in \`unique_insights\`, write a concise, well-structured paragraph with specific names, dates, metrics, and technologies wherever possible. Use references to public sources with numbered citations like \[1\], \[2\].



                7\. Output only the JSON object, nothing else.
  1. Observe the unexpected behavior.

2025-09-05 15:38:59,441 - INFO - Perplexity API raw response: {“id”: “1db228d2-bdf1-430c-86c3-28b626bbdc59”, “model”: “sonar”, “created”: 1757079539, “usage”: {“prompt_tokens”: 809, “completion_tokens”: 240, “total_tokens”: 1049, “search_context_size”: “low”, “cost”: {“input_tokens_cost”: 0.001, “output_tokens_cost”: 0.0, “request_cost”: 0.005, “total_cost”: 0.006}}, “citations”: [“https://www.xing.com/profile/Martin_Hoerbe”, “https://www.xing.com/profile/Martin_Hoerbe2”\], “search_results”: [{“title”: “Martin H\u00f6rbe - Head Global IRIS PMO & Head Single ERP …”, “url”: “https://www.xing.com/profile/Martin_Hoerbe”, “date”: “2014-09-01”, “last_updated”: “2024-11-12”, “snippet”: “Martin H\u00f6rbe, Basel Berufserfahrung, Kontaktdaten, Portfolio und weitere Infos: Erfahr mehr \u2013 oder kontaktier Martin H\u00f6rbe direkt bei XING.”}, {“title”: “Martin Hoerbe - Alcon Management SA”, “url”: “https://www.xing.com/profile/Martin_Hoerbe2”, “date”: “1999-09-01”, “last_updated”: “2025-09-05”, “snippet”: “Martin Hoerbe. Alcon Management SA. PMO Manager, Program Manager. Rheine, North Rhine-Westphalia, Germany. Martin Hoerbe. Basis.”}], “object”: “chat.completion”, “choices”: [{“index”: 0, “finish_reason”: “length”, “message”: {“role”: “assistant”, “content”: “{\n “fullname”: “Martin Hoerbe”,\n “position”: “Global Head Transformation & Operational Excellence”,\n “country”: “Germany”,\n “region”: “DACH”,\n “preferred_language”: “German”,\n “persona”: “Executives”,\n “linkedin_url”: "http://www.linkedin.com/in/martin-hoerbe-5376977\”,\n “company_website”: “https://alcon.com”,\n “company_linkedin_url”: "http://www.linkedin.com/company/alcon\“,\n “unique_insights”: {\n “unique_role_contributions”: \n \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t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\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t”}, “delta”: {“role”: “assistant”, “content”: “”}}]}

:pushpin: API Request & Response (if applicable)

:globe_showing_europe_africa: Environment

  • API Version: Sonar
  • SDK (if applicable): Python
  • Operating System: MacOs

:paperclip: Logs or Screenshots (if applicable)

Add any logs or screenshots that can help debug the issue.

:memo: Additional Context

Add any other context about the problem here.