Create spreadsheets & documents with LangChain
Give a LangChain agent a tool to produce real, shareable spreadsheets and documents instead of dumping text. Wrap the OpenOfficeAI API in a @tool function and the LLM can generate a budget, report, or invoice and return a link the user can open. Below is a complete tool definition for a modern LangChain agent.
import requests
from langchain_core.tools import tool
@tool
def create_spreadsheet(title: str, rows: list[list]) -> str:
"""Create a shareable spreadsheet. 'rows' is a list of rows,
the first row being the header. Returns a public URL."""
resp = requests.post(
"https://openofficeai.com/api/v1/sheets",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"title": title, "sheets": [{"rows": rows}]},
)
return resp.json()["url"]
# Bind it to your model:
# llm_with_tools = llm.bind_tools([create_spreadsheet])How to create a spreadsheet with LangChain
- 1Define a @tool that wraps a POST to /api/v1/sheets and returns the url field.
- 2Give the tool a clear docstring — the LLM uses it to decide when and how to call it.
- 3Bind the tool to your model with llm.bind_tools([create_spreadsheet]).
- 4The agent now returns shareable spreadsheet links instead of pasting raw tables into chat.
Why use OpenOfficeAI with LangChain
- Turns "here is a table" into "here is a link you can open and edit."
- Clean JSON in/out — the schema is simple enough for reliable tool calls.
- Pair with a create_document tool (/api/v1/docs) for reports and memos.
Frequently asked questions
Why give an agent a spreadsheet tool instead of generating CSV text?
A link is more useful than a wall of text: the user can open, edit, and share it, and your agent stays within token limits instead of streaming large tables. The tool returns a single URL, which is easy for the model to hand back.
How do I make tool calls reliable?
Keep the tool signature simple (title + rows) and write a precise docstring describing the row format. The flat JSON schema of the API maps cleanly to function-calling, which reduces malformed calls.
Does this work with other agent frameworks?
Yes. The same HTTP call works in CrewAI, AutoGen, OpenAI function-calling, and Claude tool use / MCP — anywhere you can define a tool that makes an HTTP request, you can give your agent document-creation ability.
Start creating documents with LangChain
Free tier includes 500 API calls per month — no card required.
Related integrations