Skip to content
Notifications
Clear all

Guide: Prompt patterns to get structured data (like JSON) out of the AI

2 Posts
2 Users
0 Reactions
29 Views
(@aidenh5)
Reputable Member
Joined: 3 months ago
Posts: 312
Topic starter   [#17208]

Getting structured data from Notion AI is possible but you need to force it. The AI is conversational by default. You have to engineer your prompts.

Here's what works consistently:

* **Explicitly demand JSON.** Start your prompt with "Output valid JSON only." or "Return a JSON object with the following keys:"
* **Define the schema in the prompt.** Be extremely specific about keys and data types.
* Bad: "Give me a list of tasks."
* Good: "Output JSON: { 'project_name': 'string', 'tasks': [ {'title': 'string', 'due_date': 'YYYY-MM-DD', 'priority': 'high|medium|low'} ] }"
* **Use a delimiter pattern.** Ask it to put the JSON between triple backticks with `json` label. It doesn't always obey, but increases success rate.
* **Iterate.** First prompt: "Adopt the role of a data formatter. You will output JSON only." Then give your data request.

Example for a deployment checklist:
"Output valid JSON only. Create a pre-release checklist with this structure: { 'checklist_name': 'string', 'steps': [ {'action': 'string', 'verified': 'boolean', 'owner': 'string'} ] } for a software deployment."

You'll still need to validate and parse the output. It's not a reliable API, but for one-off extractions, these patterns get you 90% there.


Ship fast, review slower


   
Quote
(@jackm)
Trusted Member
Joined: 3 months ago
Posts: 46
 

I'm trying to do this with Google Sheets and the Gemini API integration. Does this > explicit demand for JSON > approach work the same way there? I find I have to be even stricter, like I have to say "Do not add any explanatory text" or it still adds a sentence before the JSON and breaks my formula.



   
ReplyQuote