OpenForm
AITools

render

Last updated on

Render an OpenForm form to PDF, markdown, or DOCX

Renders a form artifact to PDF, markdown, or DOCX. Validates, fills with data, and renders via the appropriate renderer. Output is always inline (base64 for binary, utf-8 for text).

Only form artifacts can be rendered.

Input modes

The render tool accepts three input modes via a discriminated union on the source field:

ModeFieldsResolution
source: "artifact"artifact, baseUrl?Direct — no artifact fetch needed. File-backed layers use baseUrl to fetch templates.
source: "url"urlFetches artifact JSON, derives baseUrl from URL dirname
source: "registry"registryUrl, artifactNameFetches registry.json, finds item, fetches artifact

All modes share these fields:

ParameterTypeRequiredDescription
dataRecord<string, unknown>YesData to fill before rendering
layerstringNoLayer key to render. Falls back to defaultLayer, then first layer

Response

FieldTypeDescription
successbooleanWhether the render completed successfully
artifactKindstringDetected artifact kind
contentstringRendered content
encodingstringContent encoding: utf-8 or base64
mimeTypestringMIME type of the rendered output
errorstringError message if rendering failed
errorsarrayList of fill errors, each with field and message
validationIssuesarrayList of schema validation issues, each with message and optional path

Direct usage

From artifact JSON

import { executeRender } from "@open-form/ai-tools"

const result = await executeRender({
  source: "artifact",
  artifact: myFormArtifact,
  data: { fields: { name: "Jane Doe" } },
  layer: "markdown",
})

All execute functions (executeRender, executeValidateArtifact, executeFill, executeGetRegistry, executeGetArtifact) accept an optional second config parameter for custom fetch or proxy text renderer settings. See the configuration reference.

From URL

const result = await executeRender({
  source: "url",
  url: "https://public.open-form.dev/pet-addendum/pet-addendum.json",
  data: {
    fields: { petName: "Buddy", species: "dog" },
    parties: { tenant: { id: "t1", name: "Jane Doe" } },
  },
  layer: "markdown",
})

From registry

const result = await executeRender({
  source: "registry",
  registryUrl: "https://public.open-form.dev",
  artifactName: "pet-addendum",
  data: {
    fields: { petName: "Buddy", species: "dog", weight: 45, isVaccinated: true },
    parties: {
      tenant: { id: "t1", name: "Jane Doe" },
      landlord: { id: "l1", name: "Acme Properties LLC" },
    },
  },
  layer: "pdf",
})
// result.encoding === "base64", result.mimeType === "application/pdf"

Example responses

Successful text render

{
  "success": true,
  "artifactKind": "form",
  "content": "# Pet Addendum\n\nPet Name: Buddy\nSpecies: dog\n...",
  "encoding": "utf-8",
  "mimeType": "text/markdown"
}

Successful PDF render

{
  "success": true,
  "artifactKind": "form",
  "content": "JVBERi0xLjcK...",
  "encoding": "base64",
  "mimeType": "application/pdf"
}

Fill validation failure

{
  "success": false,
  "artifactKind": "form",
  "errors": [
    { "field": "petName", "message": "Missing required field: petName" }
  ]
}

On this page