Post-processing
Turn the extraction result into the JSON you want with LLM steps and Node.js or Python code steps in an IDP template: the input/output/params contract and how data flows from one step to the next.
Post-processing
Post-processing turns the extraction result into the JSON you want to return. It is a list of steps run top to bottom, each with the card controls described in Pipeline.
There are two kinds of step:
| Kind | What it does |
|---|---|
| LLM | Restructures the result from a natural-language instruction. |
| Code | Transforms the result with a Node.js or Python script. |
With no steps, the extraction result is returned as is.
How data flows between steps
Each step receives the pipeline's current result and hands over a new result, which becomes the input of the next step. The last step's output is the final result, which goes on to the validations and is returned to whoever called the template.
The first step receives the extraction result:
- text only — LLM OCR, or Roberty Cloud OCR without tables, forms and blocks: the text, as a string;
- with structured data: an object with the text and the extracted parts.
{
"text": "NOTA FISCAL ...",
"tables": [{ "rows": [["Item", "Qtd", "Valor"], ["Parafuso", "10", "5,00"]] }],
"forms": [{ "key": "CNPJ:", "value": "12.345.678/0001-90" }]
}
A disabled step changes nothing: the result passes through it as it arrived.
LLM step
The LLM step sends the current result to the model set in Model, along with your Instruction, for example "Return a JSON with the fields number, issuedAt and total.". Objects are sent to the model as JSON.
When the call to the template carries parameters, they are also sent to the model, after the result, so the instruction can use them.
The model's answer becomes the step's output. If it is a JSON — even when wrapped in a Markdown code block — the step hands over the parsed object or list; otherwise, it hands over the text.
LLM steps need the generative AI feature enabled on the workspace; without it, the option shows as locked. Contact your account manager to have the feature turned on.
Code step
The Code step runs a script in Node.js (default) or Python, picked on the editor's bar. The contract is the same in both languages:
| Variable | What it is |
|---|---|
input | The pipeline's current result: the extraction result or the previous step's output. |
output | Where the script writes its result. The value assigned becomes the step's output. |
params | Node.js only: the parameters sent with the call to the template. With no parameters, it is {}. |
A new step starts with output = input, which passes the result on unchanged. If the code is empty, the step also returns its input as is.
Node.js example that builds a JSON from the tables and the text:
const rows = input.tables?.[0]?.rows ?? [];
const numero = input.text.match(/N[ºo°]\s*(\d+)/)?.[1] ?? null;
output = {
numero,
itens: rows.slice(1).map(([item, quantidade, valor]) => ({ item, quantidade, valor })),
cliente: params.cliente ?? null,
};
In Python, without params:
tables = input.get("tables") or []
rows = tables[0]["rows"] if tables else []
output = {
"linhas": len(input["text"].splitlines()),
"itens": [
{"item": row[0], "quantidade": row[1], "valor": row[2]}
for row in rows[1:]
],
}
In Node.js, the script runs isolated, with a 5-second limit and only the language's basic features (JSON, Math, Date, Object, Array, String, Number, Boolean): there is no require and no network access, and anything written with console.log does not show up in the result. If the script throws an error, the run ends as Failed.
The editor suggests the fields of input and params from the last Playground run: run the Playground once with a sample document before writing the code.
Tips
- Use Roberty Cloud OCR with tables and a code step when the document has a fixed structure; use an LLM step when the layout varies and it is easier to describe the result than to program it.
- Combine both: an LLM step that returns a JSON, followed by a code step that adjusts formats such as dates and amounts.
- In the Playground, the Post-processing tab shows each step's output, so you can check where the result changed.