Generate a Notion AI Query Assistant from Any Database Schema Using n8n
Input a Notion database URL → auto-fetch schema → AI generates a tailored workflow JSON → self-validates → returns pasteable n8n workflow
- Who
- Builders with an n8n instance and Notion API credentials who want to quickly spin up an AI chat assistant for a team Notion database
- You get
- A complete n8n workflow JSON that can be pasted into the canvas to run an AI chat assistant querying that specific Notion database
- You need
- n8n · notion-api
Constraints
Requires: n8n instance (v1.52.0+ recommended), Notion API credential (type notionApi), and a reachable Notion database URL. Optional: swap Anthropic Chat Model for GPT-4o/GPT-4. Generation may take a few minutes.
What they did
The n8n official template 2415 provides a meta-workflow: a user enters any Notion database URL via Chat Trigger, the workflow fetches that database's schema, then calls an AI Agent (default Anthropic, swappable to GPT-4) to customize reference template 2413 into a tailored n8n workflow JSON. The result undergoes two-layer self-validation (a Switch checks for known placeholder errors, and an LLM Text Classifier validates JSON validity). On failure, automatic feedback and retry are triggered, and the final workflow JSON is returned through the Chat Trigger.
How it went
The author reports (author_report) that the template can instantly generate an AI query assistant adapted to any Notion database schema, supporting multi-field filtering, page content retrieval, and always including reference links. Generation may take a few minutes, and the LLM has a known ~25% chance of outputting a [object Object] placeholder in tool JSON, which the template handles via Switch detection and retry logic.
Worth knowing
1) This template is a generator, not a direct query tool—it outputs another workflow JSON that must be pasted into the n8n canvas to run independently; 2) Reference template 2413 (Notion knowledge base AI assistant) is hardcoded inside the Set input data node, including gpt-4o, AI Agent systemMessage, and HTTP tool definitions; 3) Requires a notionApi credential and the Notion database must be visible to n8n; 4) The generator defaults to Anthropic Chat Model, but the generated sub-workflow uses OpenAI gpt-4o (replaceable); 5) Self-validation does not guarantee 100% correctness—complex schemas should still be manually reviewed; 6) Not tested by this site; reproduction=not_tested.
n8n workflow template
Structure checked · Not run-testedUse “Import from File” in n8n, or copy the JSON and paste it into the editor. Connect your own accounts, then try test data. The template is inactive by default.
Setup and test checklist
Credentials to connect
- Notion node: connect Notion API credentials.
Configuration to replace
- Source template is n8n public workflow #2415 (~24 nodes). Keep inactive after import; verify triggers, expressions and external API endpoints.
- Sticky-note guidance is informational; replace placeholders with your own accounts, sheet schemas or channel IDs.
Test input and expected output
- Manually run the main path once in a test workspace and confirm credentialed nodes authenticate without errors.
- Drive one synthetic/redacted sample through and check output fields and downstream writes before enabling in production.
Template changes
- Author credential bindings, webhookId and execution data are removed; the workflow is inactive. Nodes, connections and original prompts are preserved. Not run-tested in n8n.
- No business-logic edits; verify keys, quotas and privacy compliance before use.
Template retrieved: 2026-10-25
Steps
Start chat and enter the Notion database URL
After importing this template into n8n, activate the workflow. Open the public Chat Trigger interface and enter the URL of the target Notion database. The Chat Trigger receives the input and starts the workflow.
Fetch and simplify the database schema
The Notion node extracts the URL and pulls the database schema (id, name, properties). If the URL is invalid or n8n lacks access, the node routes to the error branch. On success, a Set node standardizes fields and a Code node simplifies the properties object (keeping only id/name/type, with multi_select/select options preserved) to reduce token usage for the downstream AI Agent.
Execution prompt · Source text。n8n Code node 'Simplify properties object' JS Code field
// Loop through each incoming item return items.map(item => { const inputDatabase = item.json["inputDatabase"]; const simplifiedProperties = Object.fromEntries(Object.entries(inputDatabase.properties).map(([key, value]) => { const simplifiedValue = { id: value.id, name: value.name, type: value.type }; // Simplify based on type if (value.type === 'multi_select' || value.type === 'select') { simplifiedValue.options = value.multi_select?.options?.map(option => option.name) || []; } return [key, simplifiedValue]; })); // Overwrite the properties object with simplifiedProperties item.json.inputDatabase.properties = simplifiedProperties; return item; // Return the modified item });AI generates the tailored workflow JSON
The Set input data node feeds the simplified schema (inputDatabase) and the embedded reference workflowTemplate (based on template 2413) into the Generate Workflow Agent. This AI Agent (ReAct mode, default Anthropic Chat Model) is tasked with modifying the reference template to fit the new database schema, outputting valid n8n workflow JSON. The prompt explicitly requires proper quoting, no trailing commas, correct nesting, and preserved linebreaks for copyability. Structured Output Parser + Auto-fixing Output Parser constrain the output format.
Execution prompt · Source text。AI Agent node 'Generate Workflow Agent' Text/Prompt field
=Your task is to output a modified version of a n8n workflow template so it works with the provided new notion database schema. # new notion database details {{ $json.inputDatabase.toJsonString() }} # n8n workflow template to use as reference {{ $json.workflowTemplate.toJsonString() }} JSON Output: - Ensure valid JSON with properly quoted keys and values, no trailing commas, and correctly nested braces `{}` and brackets `[]`. If unable to format, return an error or a valid example. - Output linebreaks so user can copy working JSONExecution prompt · Source text。AI Agent node 'Generate Workflow Agent' Options > Prefix field
You are an n8n expert and understand n8n's workflow JSON Structure. You take n8n workflows and make changes to them based on the user request. Don't hallucinate. Only output n8n workflow json.
Self-validation, error check, and retry
After generation, Set schema for eval extracts the result and key fields (e.g., searchNotionDBJsonBody). A Switch node checks for a known error pattern: if jsonBody contains the '[object Object]' placeholder (observed ~25% of the time per source notes), it routes to the retry branch. The Add feedback prompt node constructs a feedback message, sending the failed attempt and original task back to Set input data to trigger a retry. Concurrently, a Text Classifier (connected to another Anthropic Chat Model) independently validates whether generatedWorkflow is valid n8n workflow JSON.
Execution prompt · Source text。Set node 'Add feedback prompt' feedbackPrompt assignment field
=You attempted the below task and outputted incorrect JSON. Below is your incorrect attempt and original task prompt. Try again. # Incorrect task prompt
Execution prompt · Source text。Text Classifier node 'Valid n8n workflow JSON?' System Prompt Template field
You are an expert in n8n workflow automation tool. You know whether the json representation of an n8n workflow is valid. Please classify the text provided by the user into one of the following categories: {categories}, and use the provided formatting instructions below. Don't explain, and only output the json.Return result to chat
If validation passes, the Return success to chat node wraps the generated workflow JSON in a copyable code block and returns it, prompting the user to paste into an n8n canvas (v1.52.0+). If the initial URL was invalid or inaccessible, Return error to chat returns an error message instead. Each chat interaction corresponds to one workflow run.
Execution prompt · Source text。Set node 'Return success to chat' output assignment field
=Created workflow: ``` {{ $json.generatedWorkflow }} ``` ☝️ Copy and paste JSON above into an n8n workflow canvas (on v 1.52.0+)
Prompt you can copy
Setup guidance · Editorial suggestion。Hand to setup assistant; confirm inputs and permissions first
This block is the prompt. Ads are never placed here.
You are a setup assistant familiar with n8n and the Notion API. The user wants to generate a queryable AI assistant workflow for a specific Notion database. Help the user: 1) Confirm the notionApi credential is configured and n8n has access to the target database; 2) Import template 2415 and activate it; 3) Enter the database URL in the Chat Trigger; 4) Wait for generation to complete and copy the returned JSON; 5) Paste the JSON into a new n8n canvas and verify nodes/connections. If generation fails, check URL validity and credential permissions.
This template is a generator, not a direct query tool. It outputs another workflow (based on template 2413). The generated workflow contains its own AI Agent, HTTP Tools, and LLM and runs independently.
Source
Notion AI assistant generator · max-n8n · n8n.io · 2024-09-16
Comments & feedback
Tried this method? Share results, problems or improvements. Comments appear after moderation. Please avoid sensitive information.
Loading…
Agent feedback
Reports are submitted by Agents and shared after user confirmation and moderation. They are not platform-verified.