Skip to content

Build AI methods with your coding agent, then run them anywhere: as an MCP for chatbots, as a webapp for people, or via API for your software.

Fix/pipe validations (#492)

Louis Choquelc7d162b8f8d0
diff --git a/pipelex/core/pipes/pipe_blueprint.py b/pipelex/core/pipes/pipe_blueprint.py
index 95e2a8a52..340784a51 100644
--- a/pipelex/core/pipes/pipe_blueprint.py
+++ b/pipelex/core/pipes/pipe_blueprint.py
@@ -188,13 +188,6 @@ class PipeBlueprint(ABC, BaseModel):
msg = f"Invalid concept string or code '{concept_string_or_code}' when trying to validate the input of a pipe blueprint: {exc}"
raise ValueError(msg) from exc
- # Check that every input_name is unique
- input_names = list(self.inputs.keys())
- if len(input_names) != len(set(input_names)):
- duplicates = [name for name in input_names if input_names.count(name) > 1]
- msg = f"Duplicate input names found: {duplicates}. Input names must be unique."
- raise ValueError(msg)
-
self.validate_inputs()
@final
diff --git a/pipelex/pipe_controllers/batch/pipe_batch.py b/pipelex/pipe_controllers/batch/pipe_batch.py
index 6b9fea6d1..da477ee9d 100644
--- a/pipelex/pipe_controllers/batch/pipe_batch.py
+++ b/pipelex/pipe_controllers/batch/pipe_batch.py
@@ -32,10 +32,13 @@ class PipeBatch(PipeController):
@override
def required_variables(self) -> set[str]:
required_variables: set[str] = set()
- # 1. Check that the inputs of the pipe branch_pipe_code are in the inputs of the pipe
- pipe = get_required_pipe(pipe_code=self.branch_pipe_code)
- required_variables.update(variable_name for variable_name, _ in pipe.inputs.items)
+ # 1. Check that the inputs of the branch_pipe are in the inputs of the pipe
+ branch_pipe = get_required_pipe(pipe_code=self.branch_pipe_code)
+ required_variables.update(branch_pipe.inputs.variables)
# 2. Check that the input_list_stuff_name is in the inputs of the pipe
+ if self.batch_params.input_item_stuff_name not in required_variables:
+ msg = f"Input item name '{self.batch_params.input_item_stuff_name}' not found in inputs of branch pipe '{self.branch_pipe_code}'"
+ raise ValueError(msg)
required_variables.remove(self.batch_params.input_item_stuff_name)
required_variables.add(self.batch_params.input_list_stuff_name)
return required_variables
@@ -54,7 +57,11 @@ class PipeBatch(PipeController):
@override
def validate_inputs_with_library(self):
- pass
+ # Check that the item name is in the inputs of the branch_pipe
+ branch_pipe = get_required_pipe(pipe_code=self.branch_pipe_code)
+ if self.batch_params.input_item_stuff_name not in branch_pipe.inputs.variables:
+ msg = f"Input item name '{self.batch_params.input_item_stuff_name}' not found in inputs of branch pipe '{self.branch_pipe_code}'"
+ raise ValueError(msg)
@override
def validate_output_static(self):
diff --git a/pipelex/pipe_controllers/batch/pipe_batch_blueprint.py b/pipelex/pipe_controllers/batch/pipe_batch_blueprint.py
index 9f31a06cc..f0dcf59ff 100644
--- a/pipelex/pipe_controllers/batch/pipe_batch_blueprint.py
+++ b/pipelex/pipe_controllers/batch/pipe_batch_blueprint.py
@@ -20,7 +20,18 @@ class PipeBatchBlueprint(PipeBlueprint):
@override
def validate_inputs(self):
- pass
+ # The PipeBatch will iterate over a list and pass each item to the branch pipe,
+ # so we must have the list's name as part of the batch inputs
+ # and conversely, we must not have the item's name as part of the batch inputs
+ if not self.inputs or self.input_list_name not in self.inputs:
+ msg = f"Input list name '{self.input_list_name}' not found in inputs: {self.inputs}"
+ raise ValueError(msg)
+ if not self.input_item_name:
+ msg = "Empty input item name is not allowed"
+ raise ValueError(msg)
+ if self.input_item_name in self.inputs:
+ msg = f"Input item name '{self.input_item_name}' found in inputs: {self.inputs}"
+ raise ValueError(msg)
@override
def validate_output(self):
diff --git a/tests/unit/pipelex/builder/pipe/pipe_controller/pipe_batch/test_data.py b/tests/unit/pipelex/builder/pipe/pipe_controller/pipe_batch/test_data.py
index f9479d303..646080209 100644
--- a/tests/unit/pipelex/builder/pipe/pipe_controller/pipe_batch/test_data.py
+++ b/tests/unit/pipelex/builder/pipe/pipe_controller/pipe_batch/test_data.py
@@ -10,19 +10,19 @@ class PipeBatchTestCases:
PipeBatchSpec(
pipe_code="named_batch",
description="Batch with custom names",
- inputs={"data": "DataList"},
+ inputs={"widgets": "Widget[]"},
output="Results",
branch_pipe_code="transform_data",
- input_list_name="data_list",
- input_item_name="current_data",
+ input_list_name="widgets",
+ input_item_name="widget",
),
PipeBatchBlueprint(
description="Batch with custom names",
- inputs={"data": "DataList"},
+ inputs={"widgets": "Widget[]"},
output="Results",
branch_pipe_code="transform_data",
- input_list_name="data_list",
- input_item_name="current_data",
+ input_list_name="widgets",
+ input_item_name="widget",
),
)
diff --git a/tests/unit/pipelex/core/bundles/test_data_pipe_sorter.py b/tests/unit/pipelex/core/bundles/test_data_pipe_sorter.py
index ce04e1ff0..e217a41f1 100644
--- a/tests/unit/pipelex/core/bundles/test_data_pipe_sorter.py
+++ b/tests/unit/pipelex/core/bundles/test_data_pipe_sorter.py
@@ -103,7 +103,7 @@ class PipeSorterTestCases:
PIPE_BATCH_PIPES: ClassVar[dict[str, PipeBlueprintUnion]] = {
"batch_pipe": PipeBatchBlueprint(
description="Batch depends on process",
- inputs={},
+ inputs={"items": "Item[]"},
output="Text",
branch_pipe_code="process_item",
input_list_name="items",
diff --git a/tests/unit/pipelex/core/test_data/pipes/controllers/batch/pipe_batch.py b/tests/unit/pipelex/core/test_data/pipes/controllers/batch/pipe_batch.py
index 7a9525584..1e0680cf2 100644
--- a/tests/unit/pipelex/core/test_data/pipes/controllers/batch/pipe_batch.py
+++ b/tests/unit/pipelex/core/test_data/pipes/controllers/batch/pipe_batch.py
@@ -9,6 +9,7 @@ description = "Domain with batch pipe"
[pipe.batch_process]
type = "PipeBatch"
description = "Process items in batch"
+inputs = { items = "Item[]" }
output = "ProcessedData"
branch_pipe_code = "process_item"
input_list_name = "items"
@@ -21,6 +22,7 @@ input_item_name = "current_item"
"batch_process": PipeBatchBlueprint(
type="PipeBatch",
description="Process items in batch",
+ inputs={"items": "Item[]"},
output="ProcessedData",
branch_pipe_code="process_item",
input_list_name="items",