moduleType: model) are executable code that processes documents on the Kodexa platform. They are the core building block for inference, transformation, and event-driven workflows.
Project Structure
A Python module has a simple structure:Module Definition (module.yml)
Every module needs amodule.yml that describes it to the platform:
- slug: Unique identifier within your organization
- orgSlug: Your Kodexa organization slug
- moduleRuntimeRef: The runtime environment that executes your module (see Module Runtimes)
- contents: Glob patterns for files to include in the deployment
Writing an Inference Module
The most common module type processes documents. The entry point is aninfer function in module/module.py:
Magic Parameter Injection
The Kodexa bridge automatically injects parameters based on your function signature. Declare only what you need:| Parameter | Type | Description |
|---|---|---|
document | Document | The Kodexa document being processed |
document_family | DocumentFamily | The document family, if available |
model_base | str | Path to the model’s base directory on disk |
pipeline_context | PipelineContext | Pipeline execution context |
model_store | ModelStore | For persisting/loading model artifacts |
assistant | Assistant | The assistant for LLM interaction |
project | Project | The project this execution belongs to |
execution_id | str | Current execution ID |
status_reporter | StatusReporter | For posting live status updates to the UI |
event | dict | The triggering event (event handler only) |
Inference Options
You can define options that are displayed in the UI and passed to your function:Status Reporting
Usestatus_reporter for live UI updates during processing:
thinking, searching, planning, reviewing, processing, analyzing, writing, waiting.
Writing an Event Handler Module
Event handler modules react to platform events (e.g., document uploads, status changes). Add theeventAware flag and implement handle_event:
Using Module Sidecars
Sidecars let you share code between modules. Reference other modules as sidecars in yourmodule.yml:
Overriding Entry Points
By default, the runtime expects amodule package with an infer function. Override this with moduleRuntimeParameters:
Example: Document Classifier
Here’s a complete example of an inference module that classifies documents:module.yml
module/module.py
Deploying
Deploy with the KDX CLI:- Create or update the module metadata in the platform
- Package all files matching
metadata.contentspatterns - Upload the implementation
Debugging a Deployment
To keep the deployment ZIP for inspection, addkeepZip: true to your metadata:
Using Your Module
Once deployed, you can add your module to an Assistant in your project through Studio. The module will appear in the list of available modules for your organization. See Working with Modules for more details.Troubleshooting
Module import errors
- Ensure your Python environment has the correct dependencies installed
- Verify import statements use the correct package name
- Check that your
metadata.contentspatterns match your project structure
Deployment failures
- Verify KDX CLI is configured:
kdx config --list - Check the
orgSlugin module.yml matches your organization - Ensure module.yml is valid YAML
- Run
kdx applyfrom the directory containing module.yml
Module not working as expected
- Add logging to your function to trace execution
- Check that you’re returning the document from your infer function
- Verify the module is receiving the expected document format
- Review execution logs in Studio
