Skip to main content

Create a processing rule

A processing rule is a Python script that picks which step processes each file a Knowledge receives. It decides from the file's name, type, content, source or any other condition you can write in code. The rule only routes the file, and the step it picks does the work.

A Knowledge uses processing rules when its Default workflow is the Classic pipeline. If the Knowledge runs a workflow graph instead, the graph decides what happens to each file and the rule isn't used.

Before you begin​

The Processing rules tab with the list of rules on the left and the selected rule's Python code on the right

Create the rule​

  1. Go to Settings → Workflows and select the Processing rules tab.
  2. Select New, then From scratch. On an empty page, select Add new. Import JSON loads a rule exported from another environment instead.
  3. Replace Untitled processing rule with a name, for example Route by file type.
  4. Write the rule's code in the editor. The next section has an example.
  5. Select Save.

Processing rules have no switch: a rule runs whenever a Knowledge or one of its sources uses it. The rule's ⋮ menu holds Download (the .py file), Export (JSON), and Delete. Deleting a rule keeps the runs that used it.

Write the rule code​

The rule returns the name of the step to run, exactly as it appears in the Steps list. This rule sends PDF files to one step, Word files to another, and skips everything else:

#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "rational-client",
# ]
# ///

from rational_client.core import File
from rational_client.utils import run


def router(resource: File, options: dict):
name = (resource.name or "").lower()

if name.endswith(".pdf"):
return "PDF extraction"
if name.endswith((".doc", ".docx")):
return "Word extraction"
return None


run(router)
  • run(router) calls router with the file and the rule's options.
  • Return a step name to run that step on the file. The step must exist and be switched on.
  • Return None to leave the file without a step. Nothing is extracted from it.
  • To also pass options to the step, return a dictionary instead: {"workflow": "PDF extraction", "options": {...}}.

Use the rule in a Knowledge​

  1. Go to Settings → Knowledge, open the Knowledge, and select the Sources tab.
  2. Leave Default workflow set to Classic pipeline.
  3. In Default processing rule, select your rule.
  4. Select Save.

To route one attached source differently, open that source's ⋮ menu, select Data processing settings, and pick its Processing rule. A source's own rule takes precedence over the Knowledge's default.

The rule runs on files added after you save. To apply it to the files already in the Knowledge, select Reprocess knowledge in the Knowledge's Options menu. See Add and manage content in a Knowledge.

Next steps​