Iteration Layer
Products
Use Cases
Resources
Pricing
Documentation navigation

LangChain

LangChain can call Iteration Layer through normal Python functions, LangChain tools, or SDK-backed application code. Use Iteration Layer when an agent needs reliable document extraction, document-to-markdown conversion, image operations, generated PDFs, or spreadsheet outputs.

Use the official Python SDK or TypeScript SDK inside your LangChain tools. This keeps authentication, request formats, and binary handling consistent with production code.

Install

For Python projects:

pip install langchain iterationlayer

For TypeScript projects:

npm install @langchain/core iterationlayer

Example Tool

from iterationlayer import IterationLayer
from langchain_core.tools import tool


client = IterationLayer(api_key="YOUR_API_KEY")


@tool
def extract_invoice_fields(file_url: str) -> dict:
    """Extract invoice fields from a PDF or image URL."""
    return client.extract_document(
        files=[
            {
                "type": "url",
                "name": "invoice.pdf",
                "url": file_url,
            }
        ],
        schema={
            "fields": [
                {"name": "vendor", "type": "TEXT", "description": "Vendor name"},
                {"name": "invoice_number", "type": "TEXT", "description": "Invoice number"},
                {"name": "total", "type": "CURRENCY_AMOUNT", "description": "Total amount"},
            ]
        },
    )
import { tool } from "@langchain/core/tools";
import { z } from "zod";
import { IterationLayer } from "iterationlayer";

const client = new IterationLayer({
  apiKey: "YOUR_API_KEY",
});

export const extractInvoiceFields = tool(
  async ({ fileUrl }) => {
    return client.extractDocument({
      files: [
        {
          type: "url",
          name: "invoice.pdf",
          url: fileUrl,
        },
      ],
      schema: {
        fields: [
          { name: "vendor", type: "TEXT", description: "Vendor name" },
          { name: "invoice_number", type: "TEXT", description: "Invoice number" },
          { name: "total", type: "CURRENCY_AMOUNT", description: "Total amount" },
        ],
      },
    });
  },
  {
    name: "extract_invoice_fields",
    description: "Extract invoice fields from a PDF or image URL.",
    schema: z.object({
      fileUrl: z.string().url(),
    }),
  },
);

Attach the tool to your agent or chain the result into downstream logic.

Tool Design

Prefer small, task-specific tools:

  • convert_document_to_markdown(file_url)
  • extract_invoice_fields(file_url)
  • generate_approval_pdf(invoice_json)
  • create_xlsx_export(rows)

Avoid exposing every API parameter directly to the model unless the agent really needs that freedom. A narrow tool with a fixed schema is easier to evaluate and safer to share with business users.

Production Guidance

Use LangChain tools for agent-operated workflows where the model should decide when to process a file. For deterministic jobs such as scheduled imports, invoice pipelines, or report generation, call Iteration Layer directly through the REST API or an official SDK.

Keep API keys on the server side, log tool inputs and outputs for review, and prefer async requests with webhooks for long-running document and generation workflows.