Integrations/PydanticAI
AI Agent

Create spreadsheets & documents with PydanticAI

In PydanticAI, register a tool with the @agent.tool decorator and your agent can create shareable spreadsheets with type-validated arguments. The function runs the API call and returns the link. Clean, typed, and model-agnostic.

PydanticAI (Python)
import requests
from pydantic_ai import Agent

agent = Agent("openai:gpt-4o")

@agent.tool_plain
def create_spreadsheet(title: str, rows: list[list[str]]) -> str:
    """Create a shareable spreadsheet (first row = header). Returns a URL."""
    r = requests.post(
        "https://openofficeai.com/api/v1/sheets",
        headers={"Authorization": "Bearer YOUR_API_KEY"},
        json={"title": title, "sheets": [{"rows": rows}]},
    )
    return r.json()["url"]

# result = agent.run_sync("Make a sheet of Q3 revenue")

How to create a spreadsheet with PydanticAI

  1. 1Create an Agent and decorate a function with @agent.tool_plain.
  2. 2Type the arguments (title, rows) — PydanticAI validates them.
  3. 3POST to /api/v1/sheets inside the tool and return the url.
  4. 4Run the agent; it calls the tool and returns the link.

Why use OpenOfficeAI with PydanticAI

Frequently asked questions

What's the difference between tool and tool_plain?

Use @agent.tool_plain when the tool doesn't need the run context; use @agent.tool when it needs access to dependencies/context. For a simple API call, tool_plain is enough.

How are arguments validated?

PydanticAI builds the JSON schema from your type hints and validates the model's arguments before calling your function, so malformed rows are rejected before they reach the API.

Can I return structured data instead of a URL string?

Yes. Return a Pydantic model (e.g. with url and id fields) and PydanticAI will serialize it for the model — useful if you want the agent to reference the document id later.

Start creating documents with PydanticAI

Free tier includes 500 API calls per month — no card required.