Skip to main content

AI Drafting

Describe a document in plain words, in any language, and get back a document definition to review, edit and render. Drafting writes a definition and nothing else: it renders nothing and stores nothing. What renders is the definition you send to generate, so drafting is never in the render path.


In the Playground​

The Playground's prompt box drafts into the editor.

  • With the editor empty, the prompt describes a new document: "a one-page packing slip with the order number as a Code 128 barcode".
  • With a definition in the editor, the prompt describes a change to it: "add a signature block", "make it bilingual".
  • Typing # starts from a catalog example instead of a description.

When the last draft is still refused, the Playground loads it anyway and names the place the renderer refused, so you can fix it by hand.


How a draft is made​

  • It knows the vocabulary. The drafting model is given the keys and values the published schema defines, and the platform's catalog of starter documents, which it may read as examples.
  • It checks its own work. Before answering, it checks its draft the way your render will read it: against the schema, and against your workspace's own fonts, images and components. It is shown each refusal and may fix it, up to three checks in one request.
  • Every answer carries its verdict. A draft either passed that check, or comes back refused with the reason and the place.
  • It is not deterministic. The same prompt can give a different draft each time. Review a draft before you save it as a template.

POST /ai:generate-definition​

Draft a definition, or change one.

Endpoint​

POST /v1/{tenantId}/ai:generate-definition

Needs the document:write scope, from a signed-in user or an API key's access token.

Request body​

FieldTypeRequiredDescription
promptstringyesWhat to draft, or what to change, in any language; up to 4,000 characters
priorDefinitionstringnoA definition, as JSON text, to change instead of starting afresh; up to 65,536 characters
{
"prompt": "A one-page packing slip with the order number as a Code 128 barcode"
}

Response​

Success (200 OK): the draft passed its check. json is the definition as JSON text: parse it before you send it to generate.

{
"json": "{ \"document\": { \"content\": [ { \"h1\": \"Packing slip\" } ] } }"
}

Refused (422 Unprocessable Entity): the last draft was still refused when the checks ran out. The draft comes back with the first refusal, so it can be fixed by hand or with another prompt that passes it as priorDefinition.

{
"type": "https://docs.docpayload.com/api-reference/errors#schema",
"title": "The definition is not on the schema",
"status": 422,
"code": "SCHEMA",
"detail": "\"tabel\" is not in this schema; this object takes: source, break, p, th, td, h1, h2, h3, h4, h5, h6, title, lang, id, ol, ul, table, image, hr, columns, svg, toc, style, header, and 8 more",
"target": "document.content.0",
"raw": "{ \"document\": { \"content\": [ { \"tabel\": [] } ] } }"
}
FieldDescription
codeThe refusal's code, one of the codes a definition is refused with
detailWhat is wrong, and what the place takes instead
targetWhere in the draft, as dotted keys and indexes
rawThe refused draft, as JSON text

Other answers​

StatusWhen
400prompt is missing, blank or too long, or priorDefinition is too long
429More than 5 requests a minute from the organization, all its callers together (rate limits)
503FEATURE_UNAVAILABLE: this deployment does not offer drafting

What it costs​

A draft is not a document. It is not counted against the monthly allowance and it is not billed. Rendering the draft is an ordinary generation, counted and billed as any other.


What leaves the platform​

Your prompt and the priorDefinition you pass are sent to the language model that drafts. The checks run on the platform: the model is shown only what each check refuses. Your data files and the documents you have generated are not sent. Leave personal data out of a prompt; put it in the data you bind at generation time instead.