A developer building a LangChain agent that processes Notion pages needs clean structured content from each page before the agent can reason over it. The Notion API returns a typed block tree: headings, paragraphs, and callouts arrive as sibling objects, and reading a full page requires iterating over block children and recursively fetching nested elements before any text is assembled. EnConvert Distill accepts the public share link for each Notion page and a schema the agent defines, and returns structured fields in one synchronous call. The @tool function returns schema-defined page content with no block tree traversal and no recursive API calls.
How to Summarise Notion with LangChain
Summarise public Notion pages in a LangChain agent using EnConvert Distill, which returns schema-defined fields from share URLs in one synchronous call
Get API keyExample
python
import os
import requests
from langchain.agents import create_agent
from langchain.tools import tool
from langchain_openai import ChatOpenAI
NOTION_SHARE_URL = os.environ["NOTION_SHARE_URL"] # a public Notion page share link
BASE_URL = "https://api.enconvert.com/v2"
headers = {
"X-API-Key": os.environ["ENCONVERT_API_KEY"],
"Content-Type": "application/json",
}
# The fields the agent receives. The response keys match these names exactly.
# Each description tells the extractor to leave a field empty rather than guess.
NOTION_SCHEMA = {
"page_title": "The page title",
"summary": (
"A three sentence summary of the page, using only text that is visible on the page. "
"Return an empty string if the page has no text content."
),
"key_points": (
"The main points the page makes, as a list. "
"Return an empty list if the page has no text content."
),
"last_edited": "The last edited date, only if the page shows one. Return an empty string otherwise.",
}
def as_text(value) -> str:
if isinstance(value, list):
return "; ".join(str(item) for item in value) or "not stated"
return str(value) if value else "not stated"
@tool
def summarise_notion_pages(urls: list[str]) -> str:
"""Reads public Notion pages from their share links and returns structured fields for each:
title, summary, key points, and last edited date. Accepts up to 50 URLs."""
# Distill accepts at most 50 URLs per call
if len(urls) > 50:
return "Too many URLs. Distill accepts at most 50 per call."
# One synchronous call: no job_id, no polling, no download step
response = requests.post(
f"{BASE_URL}/distill",
headers=headers,
json={"urls": urls, "schema": NOTION_SCHEMA},
timeout=300,
)
# Distill runs on paid plans only, and the free tier returns 402
if response.status_code == 402:
return "Distill requires a paid plan."
response.raise_for_status()
pages = []
for result in response.json()["results"]:
if result["status"] != "completed":
pages.append(f"Source: {result['url']}\nCould not be read ({result['status']}).")
continue
# A render_quality below 0.5 may mean a login wall or challenge page
render_quality = result.get("render_quality", 1.0)
if render_quality < 0.5:
pages.append(
f"Source: {result['url']}\nLow render quality ({render_quality}), skipped."
)
continue
data = result["data"] # keys match NOTION_SCHEMA exactly
if not data.get("page_title") and not data.get("summary"):
pages.append(f"Source: {result['url']}\nNo page content was found.")
continue
pages.append(
f"Source: {result['url']}\n"
f"Title: {as_text(data['page_title'])}\n"
f"Last edited: {as_text(data['last_edited'])}\n"
f"Key points: {as_text(data['key_points'])}\n"
f"Summary: {as_text(data['summary'])}"
)
return "\n\n---\n\n".join(pages)
agent = create_agent(
model=ChatOpenAI(model="gpt-4.1", temperature=0, api_key=os.environ["OPENAI_API_KEY"]),
tools=[summarise_notion_pages],
system_prompt=(
"You answer questions about Notion pages. Use summarise_notion_pages to read the "
"pages you need, answer only from what it returns, and cite the page URL for every "
"statement. If a field is not stated, say so and do not guess."
),
)
result = agent.invoke(
{
"messages": [
{
"role": "user",
"content": f"Read {NOTION_SHARE_URL} and list its key points and last edited date.",
}
]
}
)
print(result["messages"][-1].text)
What you get back
Distill returns schema-defined fields inline as structured JSON in the data object, with no polling and no block traversal. The render_quality score lets the agent detect an inaccessible page before reasoning over incomplete content. Reading Notion pages through the API requires fetching page metadata and iterating over typed block children, including recursive fetches for nested elements, while Distill returns schema-defined fields from the share URL in one synchronous call.