Common flow patterns
The following patterns describe recommended step sequences for common document processing use cases. Use them as starting points and adapt the configuration to match your documents, downstream systems, and review requirements.
Agent extraction followed by a refiner
A financial services company processes loan application packets containing income documents, bank statements, and tax forms. Extracted financial figures must be standardized, validated for consistency, and formatted before being written to a downstream loan origination system.
Flow pattern
-
Process files — Digitize incoming documents.
-
Agent classifier — Classify each document by type (pay stub, bank statement, W-2, and so on).
-
Agent extract — Extract key financial fields for each document class using a structured schema.
-
Apply refiner — Standardize currency and date formats, calculate derived values (such as monthly income from an annual figure), and handle nulls and edge cases.
-
Apply checkpoint — Validate that required fields are populated, values fall within expected ranges, and cross-field totals are consistent.
-
Post-flow UDF — Write validated, formatted results to the loan origination system via API.
-
Raw LLM extraction output can vary in format across document types and providers. Running extracted data through the refiner before writing downstream ensures the receiving system always gets consistent, predictable output.
-
Place Apply checkpoint after the refiner — not after extraction — so that validation rules operate on clean, standardized data rather than raw LLM output.
-
The post-flow UDF handles system integration, keeping the flow steps focused on document processing logic.
Flow with multiple human review checkpoints
An insurance company processes claims documents that require a two-stage review: a claims processor verifies extraction accuracy, and a senior adjuster reviews claims above a defined value threshold. Both stages must complete before results are sent downstream.
Flow pattern
-
Process files — Digitize incoming claim documents.
-
Agent classifier — Classify documents by claim type and supporting document type.
-
Agent extract — Extract claim details, policy information, and damage assessments.
-
Apply refiner — Standardize values, calculate claim totals, and flag high-value claims.
-
Apply checkpoint (stage 1) — Route all claims to the claims processor review queue for extraction verification.
-
Apply checkpoint (stage 2) — Route claims above the value threshold to the senior adjuster escalation queue.
-
Post-flow UDF — Write approved claims to the claims management system.
-
Each Apply checkpoint step maps to a different review queue in the app deployment configuration — Stage 1 to the claims processor group, Stage 2 to the senior adjuster group.
-
The stage 2 checkpoint uses a conditional validation rule based on the claim value calculated in the refiner. Claims below the threshold pass automatically.
-
Results are only sent downstream via the post-flow UDF after both review stages are complete, ensuring claims must be reviewed to exit the workflow.
Packet processing with flows
A bank processes complex account opening requests involving multiple document types submitted by a relationship banker. Each request is tracked as a packet, with component documents classified, data extracted, and results compared against existing system records before a final approval decision is generated.
Flow pattern
-
Pre-flow UDF — Fetch the existing account record from the customer relationship management (CRM) tool using the case ID passed with the document submission, making it available as context for downstream steps.
-
Process files — Digitize the submitted document packet.
-
Agent classifier — Classify each document in the packet (ID, proof of address, corporate documents, and so on).
-
Agent extract — Extract customer and entity details from each document class.
-
Apply refiner — Normalize extracted data and flag discrepancies between submitted documents.
-
Map UDF — Compare extracted data against the CRM record fetched in the Pre-flow UDF, flagging mismatches.
-
Apply checkpoint — Route cases with mismatches or missing documents to the review queue for a relationship banker or compliance officer.
-
Post-flow UDF — Update the CRM case with extraction results, mismatch flags, and approval status; trigger notifications to the banker.
-
The Pre-flow UDF fetches external context before the flow begins, making it available to all downstream steps without repeated API calls.
-
The Map UDF performs comparison logic per record, keeping that business logic in code rather than embedded in LLM prompts.
-
The Post-flow UDF closes the loop with the CRM.
LLM client calls with external integration
An underwriter processes insurance submission documents where classification depends not only on document content but on risk appetite rules stored in an external database. The classification logic requires fetching those rules at runtime and incorporating them into the LLM prompt before a decision is made.
Flow pattern
-
Process files — Digitize the submission documents.
-
Apply classifier (with custom script) — The custom script fetches the current risk appetite rules from the external rules database, constructs a classification prompt incorporating both the document content and the fetched rules, and calls the LLM through the LLM client (
CLIENTS.llm_client) to produce a classification decision. -
Agent extract — Extract submission details using the standard agent extraction step.
-
Apply refiner — Apply underwriting-specific calculations and standardization.
-
Apply checkpoint — Route submissions outside risk appetite to the senior underwriter review queue.
-
Post-flow UDF — Write the classification decision, extracted data, and review outcome to the underwriting system.
-
Instead of using the Agent classifier step, the Apply classifier step calls the LLM through the LLM client. The classification logic requires runtime context from an external system that must be incorporated into the prompt, something not supported with Agent classifier.
-
Contain LLM client calls to a single, well-defined step (Apply classifier). Don’t scatter custom LLM calls across multiple UDFs throughout the flow.
-
The prompt must explicitly instruct the model to return only one of the defined class names and handle cases where the document doesn’t match any category. The LLM client returns the model’s response as is. It doesn’t ground or validate the output, so validation logic must be built into the custom script.
-
Error handling in the custom script must account for both external API failures (rules database unavailable) and LLM output validation failures.
Agent client extraction and validation
CLIENTS.agent_client). To access the agent client in your custom functions, connect with Instabase Support.An accounts payable team processes vendor packets that contain invoices, purchase orders, and delivery receipts in no fixed order. Each document must be classified, its fields extracted, and the extracted values checked against the source document. Only documents that fail the checks go to a person for review.
Flow pattern
-
Process files — Digitize the incoming packets.
-
Reduce UDF (extraction) — A custom function creates an agent client (
CLIENTS.agent_client) session over all the step’s inputs, with a schema that defines a class for each document type, and callsextract_async(). In one call, the agent client classifies each document as one of the schema’s classes and extracts its fields. The step writes the records to its output. -
Reduce UDF (validation) — A second custom function creates a session with the same schema, which loads the values extracted in the previous step. The function calls
validate_async()with instructions for what to check, such as that the line items add up to the invoice total. The step writes a verdict for each field with the records. -
Apply checkpoint — With Execution Mode set to Update Flow Only, the step doesn’t run validation rules of its own. It routes documents with fields that failed agent client validation to the review queue.
-
One agent client call classifies and extracts, so the flow doesn’t need separate classification and extraction steps. The agent client checks each result against the schema and writes the records to the step output, so the custom functions don’t parse model responses or build output files.
-
Process files is required to support human review. If the documents don’t need human review, you can use a single Reduce UDF that calls
extract_async()and thenvalidate_async()on the same session, and leave out the checkpoint. The verdicts are still written to the step output. For an example, see Validating extracted fields. -
The validation session must use the same schema as the extraction session. A session loads only the extracted records whose class is in its schema.
