Perplexed on output

Hi all

I have a perplexity module with this prompt

title: {{22.extractor.result.title}}
link: {{30.url}}
You are the chief news editor. Research and write a compilation article including all information from sources. Write in 3rd person making sure to mention names and quotes as they are. Be sure not make them up. Do not include date and location at the start of your output. Create a List the sources at the end. Create a new engaging title.

Output in JSON like this
{
“title”: “Your Title Here”,
“content”: “Your content goes here.”
}

JUST RESPOND JSON DO NOT ADD ANY TEXT BEFORE OR AFTER - THE OUTPUT MUST BE PURE JSON

The output I got is a problem and parse JSON module have the same results because it’s not the correct format. Is this a problem with Perplexity or make that is adding the extra ‘’'json in front and ```at the end ? Please help but it’s not showing them below

{
  "title": "Penang Coast Battered by Large Waves and Storms, Public Advised to Stay Away",
  "content": "Penang has been hit by a series of severe weather conditions, including large waves and strong winds, causing significant damage and disruptions across the state. The combination of heavy rain, storms, and unusually high tides has led to widespread destruction, prompting authorities to warn the public to stay away from coastal areas."
}

Them parse errors are frustrating, @Gnarly_Guy.

I’m confused though by you result at the end, per https://jsonlint.com/, it’s valid JSON.

Please share the output bundle from the Perplexity module so we can help debug further.

Also, I’m familiar with OpenAI, so I wonder whether Perplexity has a JSON or structured output mode.

Let me try from the start
This is my scenario

this is the output bundle from perplexity

[
    {
        "id": "118c123f-8557-4901-badb-ad4e23d118cb",
        "model": "llama-3.1-sonar-large-128k-online",
        "created": 1726654965,
        "usage": {
            "prompt_tokens": 158,
            "completion_tokens": 830,
            "total_tokens": 988
        },
        "object": "chat.completion",
        "choices": [
            {
                "index": 0,
                "finish_reason": "stop",
                "message": {
                    "role": "assistant",
                    "content": "```json\n{\n  \"title\": \"Indonesia Grapples with Severe Shortage of Medical Doctors\",\n  \"body\": \"Indonesia is facing a critical shortage of medical doctors, a problem that has been exacerbated by the maldistribution of healthcare professionals across the country. According to the Health Ministry, Indonesia is approximately 160,000 doctors short of meeting the World Health Organization (WHO) standard of one doctor for every 1,000 people. With a population of around 270 million, the country needs a total of 270,000 doctors but currently has only about 110,000 to 226,000 doctors, depending on the source.\n\nThe current doctor-patient ratio in Indonesia stands at about 0.47 doctors per 1,000 people, significantly below the WHO's recommended standard. This shortage is particularly acute in remote and underdeveloped regions, where hundreds of health centers operate without any doctors. The annual intake of medical students at Indonesia's 92 medical schools ranges from 12,000 to 13,000, but even at this rate, it would take more than 14 years to meet the WHO's recommended ratio.\n\nThe distribution of doctors is highly skewed, with the majority concentrated on the densely populated islands of Java and Bali. For instance, West Java, East Java, and Jakarta together have around 23,000 doctors, which is nearly 40% of the country's total.\n\nTo address this issue, the Health Ministry and the Education, Culture, Research and Technology Ministry have issued a joint decree to increase admissions quotas for medical programs and expand medical specialization programs. However, the implementation of these policies faces challenges, including the need for more qualified medical lecturers and the bureaucratic hurdles in procuring medical educators.\n\nA recent proposal to hire foreign doctors to alleviate the shortage has sparked controversy. Health Minister Budi Gunadi Sadikin has defended the plan, stating that it is legally supported by the health law passed last year and that foreign doctors are needed to prevent affluent Indonesians from seeking medical treatment overseas. Indonesia spends between 100-150 trillion rupiah (U.S. $7-9 billion) annually on medical treatment abroad, with an estimated 600,000 to 1 million Indonesians seeking treatment outside the country.\n\nCritics, including Budi Santoso, the dean of the faculty of medicine at Airlangga University, argue that hiring foreign doctors undermines local expertise and could cause communication issues. Santoso was briefly fired for his criticism but was later reinstated after protests from the medical community.\n\nThe shortage of doctors is not just a numbers issue but also a matter of distribution and incentives. Many doctors prefer to work in urban areas with better infrastructure and higher salaries, leaving remote regions underserved. Ascobat Gani, a public health professor at the University of Indonesia, warned that the aging population will require more specialized doctors, such as neurologists and rheumatologists, which Indonesia's current production cannot meet.\n\nThe government acknowledges the need to improve job security and welfare for local doctors to encourage them to serve in underdeveloped areas. The Health Ministry has emphasized that foreign doctors are not a long-term solution but rather a temporary measure to address the immediate shortage.\n\nSources: https://www.kompas.id/baca/english/2022/07/20/dealing-with-shortage-of-medical-doctors-in-indonesia https://a-jhr.com/a-jhr/article/view/121 https://www.benarnews.org/english/news/indonesian/backlash-foreign-doctor-hire-plan-07192024154334.html https://www.thejakartapost.com/opinion/2024/07/13/doctors-political-puppets-in-the-local-vs-foreign-battle.html https://www.thejakartapost.com/opinion/2024/07/12/doctors-know-no-borders.html\n\"\n}\n```"
                },
                "delta": {
                    "role": "assistant",
                    "content": ""
                }
            }
        ]
    }
]

I then used input it into the Parse JSON module like this

After running, I got this error saying it’s not valid JSON

So I found this replace code from another thread and did this to try and fix it.

image

and again I get saying source is not valid JSON. Please help. I’m lost.

What a great breakdown and level of detail @Gnarly_Guy; it’s extremely helpful to have the fuller situational context.

You’ve done very well getting the major parts into place, and I’ve learned too from you about the WordPress upload and posting method which I might take for my personal blog.

Because my curiosity is too great at times, I spent a couple of hours attempting a clean solution, but failed. Through debugging using https://jsonlint.com/, I determined that the problem is the process timing of the escaped quotations alongside the newlines outside of the content.

In the end, I can get the body content, but I would suggest tossing it back to genAi to chunk the content.

Please chunk the following content for readability.

***

SOURCE MATERIALS


I’ve further ideas here, but alas my freebie time is way used up. Sorry.

blueprint.json (168.8 KB)

wow that’s a lot of modules everywhere just for a blogpost?

I just gave up and added another module to craft a title and be done with it. The only problem now I get it for Perplexity to not output html when I specifically asked it to. Some posts work fine but some are just plain text with no html

Good evening @Gnarly_Guy;

Yeah, I get too curious to know why, what, and how at times. So my investigation was a bit much.

Still, simplifying things tends to make life easier, though not always a viable option at scale.

For your HTML problem, instead of asking for such, as Perplexity to write the output as Markdown. Then use the built-in Markdown to HTML module to push into WordPress.

Thanks for the tip. I did that and it works for the first round. Don’t know how it will react with different pages.

See Issue with JSON Parsing in OpenAI Response - #2 by samliew for updated replace pattern.

Hope this helps! Let me know if there are any further questions or issues.

@samliew


P.S.: Did you know, the concepts of about 70% of questions asked on this forum are already covered in the Make Academy. Investing some effort into it will save you lots of time and frustration using Make later!