Prompt

How do I let an agent read from a database and write to Notion?

Artificial Intelligence / AI Agents1 observationLast seen Oct 9, 2026

Latest observation

Oct 9, 2026OpenAI APIWeb search: off

To let an agent read from a database and write to Notion, you typically give the agent access to two tools/integrations:

  1. A database connector for reading data
  2. A Notion integration for creating/updating pages

High-level flow

  1. Agent receives a task.
  2. Agent queries the database through a read tool.
  3. Agent transforms the data as needed.
  4. Agent writes the result to Notion through a Notion API tool.

1) Give the agent database read access

Option A: Direct SQL access

If your database is something like PostgreSQL, MySQL, or SQLite:

  • Create a read-only database user
  • Expose a tool that runs parameterized SELECT queries
  • Restrict it to approved tables/views if possible

Example tool idea:

  • run_sql(query: string) -> rows

Best practices:

  • Only allow SELECT
  • Prevent destructive queries
  • Use query validation or a whitelist
  • Prefer views over raw tables

Option B: Use an internal API

If you don’t want the agent connecting directly to the DB:

  • Create a backend endpoint like GET /agent/customer-summary
  • That endpoint queries the DB safely
  • The agent calls the endpoint instead of SQL directly

This is often safer.


2) Set up Notion access

Create a Notion integration

In Notion:

  • Go to Settings & members → Connections / Integrations
  • Create a new internal integration
  • Copy the Notion API token
  • Share the target Notion page/database with that integration

Decide what the agent will do in Notion

The agent can:

  • Create new pages
  • Update existing pages
  • Append blocks to pages
  • Insert rows into a Notion database

3) Expose a Notion write tool

Typical actions:

  • create_page(database_id, properties, content)
  • update_page(page_id, properties)
  • append_blocks(page_id, blocks)

Example usage:

  • Read a customer record from DB
  • Create a Notion page in a “Customer Notes” database
  • Populate page properties and a summary block

4) Define the agent’s tools

If you’re using an agent framework, register two tools:

  • Database read tool
  • Notion write tool

Example conceptual tool set:

  • get_customer_orders(customer_id)
  • create_notion_page(title, body, tags)

The agent then plans:

  1. Call DB tool
  2. Summarize results
  3. Call Notion tool

5) Example implementation pattern

Database read

def get_sales_data(start_date, end_date):
    query = """
    SELECT customer_name, total_amount, order_date
    FROM orders
    WHERE order_date BETWEEN %s AND %s
    """
    return db.execute(query, (start_date, end_date))

Notion write

import requests

def create_notion_page(title, summary):
    url = "https://api.notion.com/v1/pages"
    headers = {
        "Authorization": f"Bearer {NOTION_TOKEN}",
        "Notion-Version": "2022-06-28",
        "Content-Type": "application/json",
    }
    payload = {
        "parent": {"database_id": NOTION_DATABASE_ID},
        "properties": {
            "Name": {
                "title": [{"text": {"content": title}}]
            }
        },
        "children": [
            {
                "object": "block",
                "type": "paragraph",
                "paragraph": {
                    "rich_text": [{"type": "text", "text": {"content": summary}}]
                }
            }
        ]
    }
    return requests.post(url, headers=headers, json=payload).json()

6) Security considerations

Important:

  • Use read-only DB credentials
  • Limit what the agent can query
  • Store secrets securely
  • Validate and sanitize all input
  • Log tool usage
  • Add approval steps for sensitive writes

7) Common architecture choices

Simple

Agent → DB read function → Notion API write function

Safer

Agent → backend service → DB + Notion
The backend enforces rules and auditing.

More advanced

Agent with workflow orchestration:

  • Step 1: fetch data
  • Step 2: summarize
  • Step 3: human approval
  • Step 4: write to Notion

8) If you’re using a specific agent framework

Tell me which one:

  • OpenAI Assistants / Responses API
  • LangChain
  • CrewAI
  • AutoGen
  • Zapier / Make
  • Custom Python/Node agent

I can give you a concrete example for that stack, including code for:

  • database access
  • Notion integration
  • agent tool definitions

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.