Skip to main content
The processing module provides classes for tracking document processing history, recording knowledge items, and managing execution pipelines.

ProcessingStep

A ProcessingStep represents a unit of work in a document processing pipeline. Steps form a DAG (directed acyclic graph) with parent-child relationships, enabling you to track the full lineage of how a document was processed.

Creating Steps

Fields

Model Usage

model_use records the LLM calls a step made, so a document’s real model spend is visible in the Explain Plan and in model-use analytics. Steps that recorded their usage only as freeform metadata['llm_usage'] — extraction, classification and chunking steps — surface it as a typed ModelUse entry whenever the document is loaded; the freeform metadata is left in place for older readers, and a typed entry always takes precedence over it. The ModelUse class is importable from kodexa_document.processing.types.

Recording an LLM Call

record_llm_call() records a call’s usage together with the prompt, thinking and response blocks shown in the Explain Plan:
A provider outside that fixed set is stored as other, with the name you passed kept on original_provider_name. A ModelUse entry is added only when at least one usage field is set — a model, provider, token count, cost, duration, finish reason or request id. A wrapper that only narrates the prompt and response therefore leaves the platform’s own recorded entry as the step’s single usage record. The prompt, thinking, response and schema body blocks are recorded either way.

Parent-Child Relationships

Build processing hierarchies:

Merging Steps

Combine multiple processing branches:

Serialization

Steps serialize to JSON with circular reference handling:
The to_dict() method uses a seen set to handle circular references from bidirectional parent-child links. The from_dict() method uses a step_cache to reconstruct these references.

KnowledgeItem

A KnowledgeItem represents a piece of knowledge produced or consumed during processing.

Fields

KnowledgeFeature

A KnowledgeFeature attaches structured metadata to knowledge items.

Fields

Attaching to Processing Steps

Knowledge items are associated with processing steps:

PipelineContext

PipelineContext tracks the state of a running execution pipeline. It is primarily used by module developers building custom processing steps.

Fields

Status Updates

Report progress during execution:

Cancellation

Check for user-initiated cancellation:

RemoteStep

RemoteStep wraps a reference to a module on the platform and can process documents remotely:

Complete Example