A developer building a LangChain agent that reads shared Google Docs needs clean structured content that the @tool function returns to the AgentExecutor before the agent can reason over it. Google Docs shared via “anyone with the link” serve a full Drive UI with comment sidebars, suggestion overlays, and navigation chrome that obscures the document body, and the Drive API requires OAuth credentials and a GCP project before a single document can be read programmatically. EnConvert Distill accepts the shared Google Doc URL, applies a schema the tool defines, and returns structured fields in one synchronous call. The @tool function returns schema-defined document content ready for downstream reasoning with no Drive API credentials.
How to Summarise Google Docs with LangChain
Google Docs summarisation in LangChain: EnConvert Distill returns schema-defined fields from up to 50 shared URLs in one synchronous call, no Drive API setup
Get API keyExample
python
import os
import requests
from langchain.agents import create_agent
from langchain.tools import tool
from langchain_openai import ChatOpenAI
GOOGLE_DOC_URL = os.environ["GOOGLE_DOC_URL"] # a Google Doc shared as "Anyone with the link can view"
BASE_URL = "https://api.enconvert.com/v2"
headers = {
"X-API-Key": os.environ["ENCONVERT_API_KEY"],
"Content-Type": "application/json",
}
DOC_SCHEMA = {
"title": "The document title",
"summary": "A three sentence summary of what the document covers",
"key_points": "The main points or decisions in the document, as a list",
"author": "The document owner or author, if the page shows one",
"last_edited": "The date the document was last edited, if the page shows one",
}
@tool
def summarise_google_docs(urls: list[str]) -> str:
"""Reads shared Google Docs and returns structured fields for each document:
title, summary, key points, author, and last edited date. Accepts up to 50 URLs."""
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": DOC_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()
documents = []
for result in response.json()["results"]:
if result["status"] != "completed":
documents.append(f"Source: {result['url']}\nCould not be read ({result['status']}).")
continue
render_quality = result.get("render_quality", 1.0)
if render_quality < 0.5:
documents.append(
f"Source: {result['url']}\nLow render quality ({render_quality}), skipped."
)
continue
data = result["data"] # keys match DOC_SCHEMA exactly
points = data["key_points"]
documents.append(
f"Source: {result['url']}\n"
f"Title: {data['title']}\n"
f"Author: {data['author']}\n"
f"Last edited: {data['last_edited']}\n"
f"Key points: {'; '.join(points) if isinstance(points, list) else points}\n"
f"Summary: {data['summary']}"
)
return "\n\n---\n\n".join(documents)
agent = create_agent(
model=ChatOpenAI(model="gpt-4.1", temperature=0, api_key=os.environ["OPENAI_API_KEY"]),
tools=[summarise_google_docs],
system_prompt=(
"You summarise shared Google Docs. Use summarise_google_docs to read the documents "
"you need, answer only from what it returns, and cite the document URL for every statement."
),
)
result = agent.invoke(
{
"messages": [
{
"role": "user",
"content": f"Read {GOOGLE_DOC_URL} and summarise it, listing its key points.",
}
]
}
)
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, no job_id, and no signed URL to fetch. The render_quality score lets the agent detect a login wall or challenge page before reasoning over incomplete content. The Google Drive API requires OAuth 2.0 credentials, a Google Cloud project, and a separate export call before a @tool function can return document content to the agent; Distill requires only the shared link and an API key.