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/output multiplicity validation (#526)
Thomas Hebrard4960b78969ad
diff --git a/.gitignore b/.gitignoreindex 60dbdb2c1..f1a7b7572 100644--- a/.gitignore+++ b/.gitignore@@ -57,3 +57,4 @@ gcp_credentials.json/pipelex.tomlsettings.local.jsonstructures/+telemetry_override.tomldiff --git a/CHANGELOG.md b/CHANGELOG.mdindex 7d2d99bd8..f6e45be1b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -39,6 +39,7 @@- Context manager support for the `Pipelex` class (`with Pipelex.make(): ...`) for graceful shutdown- Validation for `PipeCompose` output concepts: must be strictly compatible with the Text concept- Validation for Pipelex Bundle concept keys: cannot create a native concept+- Validation for `PipeSequence`: The multiplicity of the output of the sequence must be the same as the multiplicity of the output of the last step.### Changed@@ -81,6 +82,7 @@### Refactored- `ConceptFactory.make_from_blueprint` method now correctly handles native concepts+- The output (and inputs) of a pipe is now a `StuffSpec` object instead, that holds the concept and the multiplicity.## [v0.17.3] - 2025-12-01diff --git a/pipelex/builder/builder_loop.py b/pipelex/builder/builder_loop.pyindex 222c40eba..912e38caa 100644--- a/pipelex/builder/builder_loop.py+++ b/pipelex/builder/builder_loop.py@@ -130,8 +130,8 @@ class BuilderLoop:continuematch val_error.error_type:- case PipeValidationErrorType.INPUT_REQUIREMENT_MISMATCH:- # Fix input requirement mismatch by updating the specific mismatched input(s)+ case PipeValidationErrorType.INPUT_STUFF_SPEC_MISMATCH:+ # Fix input stuff spec mismatch by updating the specific mismatched input(s)# This applies to ALL pipe categories (operators and controllers)if not PipeCategory.is_controller_by_str(category_str=pipe_spec.pipe_category):continue@@ -147,12 +147,12 @@ class BuilderLoop:# Update only the mismatched inputs with the correct concept from needed_inputsfor variable_name in mismatched_variables:- for named_requirement in needed_inputs.named_input_requirements:- if named_requirement.variable_name == variable_name:+ for named_stuff_spec in needed_inputs.named_stuff_specs:+ if named_stuff_spec.variable_name == variable_name:old_value = new_inputs.get(variable_name, "NOT SET")concept_code_with_multiplicity = format_concept_with_multiplicity(- concept_code_or_string=named_requirement.concept.code,- multiplicity=named_requirement.multiplicity,+ concept_code_or_string=named_stuff_spec.concept.code,+ multiplicity=named_stuff_spec.multiplicity,)new_inputs[variable_name] = concept_code_with_multiplicity# TODO: return a structured report of what was done, let the caller decide if they want to print it or act on it@@ -174,12 +174,12 @@ class BuilderLoop:needed_inputs = pipe.needed_inputs()old_inputs = dict(pipe_spec.inputs) if pipe_spec.inputs else {}fixed_inputs: dict[str, str] = {}- for named_requirement in needed_inputs.named_input_requirements:+ for named_stuff_spec in needed_inputs.named_stuff_specs:concept_code_with_multiplicity = format_concept_with_multiplicity(- concept_code_or_string=named_requirement.concept.code,- multiplicity=named_requirement.multiplicity,+ concept_code_or_string=named_stuff_spec.concept.code,+ multiplicity=named_stuff_spec.multiplicity,)- fixed_inputs[named_requirement.variable_name] = concept_code_with_multiplicity+ fixed_inputs[named_stuff_spec.variable_name] = concept_code_with_multiplicity# Only apply fix if it actually changes something (avoid infinite loops)if fixed_inputs != old_inputs:@@ -193,8 +193,8 @@ class BuilderLoop:This might be an intermediate variable that shouldn't be in inputs.")- case PipeValidationErrorType.INADEQUATE_OUTPUT_CONCEPT:- # Fix output concept mismatch for PipeSequence by updating to match last step's output+ case PipeValidationErrorType.INADEQUATE_OUTPUT_CONCEPT | PipeValidationErrorType.INADEQUATE_OUTPUT_MULTIPLICITY:+ # Fix output concept/multiplicity mismatch for PipeSequence by updating to match last step's outputif not isinstance(pipe_spec, PipeSequenceSpec):continue@@ -213,8 +213,9 @@ class BuilderLoop:pipe_spec.output = new_outputfixed_pipes.append(pipe_spec)# TODO: return a structured report of what was done, let the caller decide if they want to print it or act on it+ error_kind = "concept" if val_error.error_type == PipeValidationErrorType.INADEQUATE_OUTPUT_CONCEPT else "multiplicity"log.info(- f"🔧 Fixed output concept for pipe '{val_error.pipe_code}': output changed from '{old_output}' → \+ f"🔧 Fixed output {error_kind} for pipe '{val_error.pipe_code}': output changed from '{old_output}' → \'{new_output}' (matching last step '{last_step_pipe_code}')")diff --git a/pipelex/builder/runner_code.py b/pipelex/builder/runner_code.pyindex 6a12258c3..eb7d49cc0 100644--- a/pipelex/builder/runner_code.py+++ b/pipelex/builder/runner_code.py@@ -17,7 +17,7 @@ from pipelex.core.concepts.concept_representation_generator import ()from pipelex.core.concepts.native.concept_native import NativeConceptCodefrom pipelex.core.domains.domain import SpecialDomain-from pipelex.core.pipes.inputs.input_requirements import InputRequirements+from pipelex.core.pipes.inputs.input_stuff_specs import InputStuffSpecsfrom pipelex.core.pipes.pipe_abstract import PipeAbstractfrom pipelex.core.pipes.variable_multiplicity import VariableMultiplicity@@ -118,7 +118,7 @@ def _collect_concept_info(concept: Concept) -> CustomClassInfo | None:)-def _collect_imports_for_inputs(inputs: InputRequirements) -> tuple[set[str], dict[str, CustomClassInfo]]:+def _collect_imports_for_inputs(inputs: InputStuffSpecs) -> tuple[set[str], dict[str, CustomClassInfo]]:"""Collect all imports needed for a pipe's inputs.Args:@@ -165,9 +165,9 @@ def generate_runner_code(pipe: PipeAbstract, output_multiplicity: bool = False)output_multiplicity: Whether the output is a list (e.g., Text[])"""# Get output information- structure_class_name = pipe.output.structure_class_name+ structure_class_name = pipe.output.concept.structure_class_nameis_native = NativeConceptCode.is_native_structure_class(structure_class_name)- custom_info = None if is_native else _collect_concept_info(pipe.output)+ custom_info = None if is_native else _collect_concept_info(pipe.output.concept)# Collect all imports needed for inputsnative_classes, custom_classes = _collect_imports_for_inputs(pipe.inputs)diff --git a/pipelex/core/memory/working_memory_factory.py b/pipelex/core/memory/working_memory_factory.pyindex 37b3c338a..e2294e492 100644--- a/pipelex/core/memory/working_memory_factory.py+++ b/pipelex/core/memory/working_memory_factory.py@@ -6,7 +6,7 @@ from pipelex import logfrom pipelex.client.protocol import PipelineInputsfrom pipelex.core.memory.exceptions import WorkingMemoryFactoryErrorfrom pipelex.core.memory.working_memory import MAIN_STUFF_NAME, StuffDict, WorkingMemory-from pipelex.core.pipes.inputs.input_requirements import TypedNamedInputRequirement+from pipelex.core.pipes.inputs.input_stuff_specs import TypedNamedStuffSpecfrom pipelex.core.stuffs.list_content import ListContentfrom pipelex.core.stuffs.stuff import Stufffrom pipelex.core.stuffs.stuff_content import StuffContent@@ -79,12 +79,12 @@ class WorkingMemoryFactory(BaseModel):return working_memory@classmethod- def create_mock_content(cls, requirement: TypedNamedInputRequirement) -> StuffContent:- """Helper method to create mock content for a requirement."""- if requirement.structure_class:+ def create_mock_content(cls, typed_named_stuff_spec: TypedNamedStuffSpec) -> StuffContent:+ """Helper method to create mock content for a typed_named_stuff_spec."""+ if typed_named_stuff_spec.structure_class:# Create mock object using polyfactory- class MockFactory(ModelFactory[requirement.structure_class]): # type: ignore[name-defined]- __model__ = requirement.structure_class+ class MockFactory(ModelFactory[typed_named_stuff_spec.structure_class]): # type: ignore[name-defined]+ __model__ = typed_named_stuff_spec.structure_class__check_model__ = True__use_examples__ = True__allow_none_optionals__ = False # Ensure Optional fields always get values@@ -92,10 +92,10 @@ class WorkingMemoryFactory(BaseModel):return MockFactory.build(factory_use_construct=True) # type: ignore[no-any-return]# Fallback to text content- return TextContent(text=f"DRY RUN: Mock content for '{requirement.variable_name}' ({requirement.concept.code})")+ return TextContent(text=f"DRY RUN: Mock content for '{typed_named_stuff_spec.variable_name}' ({typed_named_stuff_spec.concept.code})")@classmethod- def make_for_dry_run(cls, needed_inputs: list[TypedNamedInputRequirement]) -> "WorkingMemory":+ def make_for_dry_run(cls, needed_inputs: list[TypedNamedStuffSpec]) -> "WorkingMemory":"""Create a WorkingMemory with mock objects for dry run mode.Args:@@ -107,57 +107,60 @@ class WorkingMemoryFactory(BaseModel):"""working_memory = cls.make_empty()- for requirement in needed_inputs:+ for typed_named_stuff_spec in needed_inputs:try:- if not requirement.multiplicity:- mock_content = cls.create_mock_content(requirement)+ if not typed_named_stuff_spec.multiplicity:+ mock_content = cls.create_mock_content(typed_named_stuff_spec)# Create stuff with mock contentmock_stuff = StuffFactory.make_stuff(- concept=requirement.concept,+ concept=typed_named_stuff_spec.concept,content=mock_content,- name=requirement.variable_name,+ name=typed_named_stuff_spec.variable_name,code=shortuuid.uuid()[:5],)- working_memory.add_new_stuff(name=requirement.variable_name, stuff=mock_stuff)+ working_memory.add_new_stuff(name=typed_named_stuff_spec.variable_name, stuff=mock_stuff)else:# Let's create a ListContent of multiple stuffsnb_stuffs: int- if isinstance(requirement.multiplicity, bool):+ if isinstance(typed_named_stuff_spec.multiplicity, bool):# TODO: make this configurable or use existing config variablenb_stuffs = 3else:- nb_stuffs = requirement.multiplicity+ nb_stuffs = typed_named_stuff_spec.multiplicityitems: list[StuffContent] = []for _ in range(nb_stuffs):- item_mock_content = cls.create_mock_content(requirement)+ item_mock_content = cls.create_mock_content(typed_named_stuff_spec)items.append(item_mock_content)mock_list_content = ListContent[StuffContent](items=items)# Create stuff with mock contentmock_stuff = StuffFactory.make_stuff(- concept=requirement.concept,+ concept=typed_named_stuff_spec.concept,content=mock_list_content,- name=requirement.variable_name,+ name=typed_named_stuff_spec.variable_name,code=shortuuid.uuid()[:5],)- working_memory.add_new_stuff(name=requirement.variable_name, stuff=mock_stuff)+ working_memory.add_new_stuff(name=typed_named_stuff_spec.variable_name, stuff=mock_stuff)except Exception as exc:log.warning(- f"Failed to create mock for '{requirement.variable_name}' ({requirement.concept.code}): {exc}. Using fallback text content.",+ f"Failed to create mock for '{typed_named_stuff_spec.variable_name}' ({typed_named_stuff_spec.concept.code}): "+ f"{exc}. Using fallback text content.")# Create fallback text content- fallback_content = TextContent(text=f"DRY RUN: Fallback mock for '{requirement.variable_name}' ({requirement.concept.code})")+ fallback_content = TextContent(+ text=f"DRY RUN: Fallback mock for '{typed_named_stuff_spec.variable_name}' ({typed_named_stuff_spec.concept.code})"+ )fallback_stuff = StuffFactory.make_stuff(- concept=requirement.concept,+ concept=typed_named_stuff_spec.concept,content=fallback_content,- name=requirement.variable_name,+ name=typed_named_stuff_spec.variable_name,code=shortuuid.uuid()[:5],)- working_memory.add_new_stuff(name=requirement.variable_name, stuff=fallback_stuff)+ working_memory.add_new_stuff(name=typed_named_stuff_spec.variable_name, stuff=fallback_stuff)return working_memorydiff --git a/pipelex/core/pipes/exceptions.py b/pipelex/core/pipes/exceptions.pyindex b8c4a8f1b..b4d31a593 100644--- a/pipelex/core/pipes/exceptions.py+++ b/pipelex/core/pipes/exceptions.py@@ -103,8 +103,9 @@ class PipeValidationErrorType(StrEnum):# Errors that are auto-fixed in builder_loop.pyMISSING_INPUT_VARIABLE = "missing_input_variable" # AUTO-FIXEDEXTRANEOUS_INPUT_VARIABLE = "extraneous_input_variable" # AUTO-FIXED- INPUT_REQUIREMENT_MISMATCH = "input_requirement_mismatch" # AUTO-FIXED+ INPUT_STUFF_SPEC_MISMATCH = "input_stuff_spec_mismatch" # AUTO-FIXEDINADEQUATE_OUTPUT_CONCEPT = "inadequate_output_concept" # AUTO-FIXED+ INADEQUATE_OUTPUT_MULTIPLICITY = "inadequate_output_multiplicity" # AUTO-FIXEDCIRCULAR_DEPENDENCY_ERROR = "circular_dependency_error"diff --git a/pipelex/core/pipes/inputs/exceptions.py b/pipelex/core/pipes/inputs/exceptions.pyindex ea418c91e..8934702be 100644--- a/pipelex/core/pipes/inputs/exceptions.py+++ b/pipelex/core/pipes/inputs/exceptions.py@@ -1,20 +1,45 @@from pipelex.base_exceptions import PipelexError+from pipelex.pipe_run.exceptions import PipeRunError+from pipelex.pipe_run.pipe_run_mode import PipeRunMode-class PipeRunInputsError(PipelexError):- def __init__(self, message: str, pipe_code: str, missing_inputs: dict[str, str]):- self.pipe_code = pipe_code- self.missing_inputs = missing_inputs- super().__init__(message)+class InputStuffSpecsError(PipelexError):+ pass+++class InputStuffSpecsFactoryError(InputStuffSpecsError):+ pass+++class InputStuffSpecNotFoundError(InputStuffSpecsError):+ passclass PipeInputError(PipelexError):- def __init__(self, message: str, pipe_code: str, variable_name: str, concept_code: str | None = None):+ def __init__(+ self,+ message: str,+ pipe_code: str,+ variable_name: str | None = None,+ concept_code: str | None = None,+ ):self.pipe_code = pipe_codeself.variable_name = variable_nameself.concept_code = concept_codesuper().__init__(message)-class PipeInputNotFoundError(PipelexError):- pass+class PipeRunInputsError(PipeRunError):+ def __init__(+ self,+ message: str,+ run_mode: PipeRunMode,+ pipe_code: str,+ missing_inputs: dict[str, str],+ variable_name: str | None = None,+ concept_code: str | None = None,+ ):+ self.missing_inputs = missing_inputs+ self.variable_name = variable_name+ self.concept_code = concept_code+ super().__init__(message, run_mode, pipe_code)diff --git a/pipelex/core/pipes/inputs/input_requirements.py b/pipelex/core/pipes/inputs/input_requirements.pydeleted file mode 100644index f000e7d62..000000000--- a/pipelex/core/pipes/inputs/input_requirements.py+++ /dev/null@@ -1,167 +0,0 @@-import json-from collections.abc import Callable-from typing import Any--from pydantic import BaseModel, Field, RootModel, field_validator--from pipelex import log-from pipelex.core.concepts.concept import Concept-from pipelex.core.concepts.concept_representation_generator import ConceptRepresentationFormat-from pipelex.core.pipes.inputs.exceptions import PipeInputNotFoundError-from pipelex.core.pipes.variable_multiplicity import VariableMultiplicity-from pipelex.core.stuffs.stuff_content import StuffContent---class InputRequirement(BaseModel):- concept: Concept- multiplicity: VariableMultiplicity | None = None---class NamedInputRequirement(InputRequirement):- variable_name: str- requirement_expression: str | None = None---class TypedNamedInputRequirement(NamedInputRequirement):- structure_class: type[StuffContent]-- @classmethod- def make_from_named(- cls,- named: NamedInputRequirement,- structure_class: type[StuffContent],- ) -> "TypedNamedInputRequirement":- return cls(**named.model_dump(), structure_class=structure_class)---InputRequirementsRoot = dict[str, InputRequirement]---class InputRequirements(RootModel[InputRequirementsRoot]):- root: InputRequirementsRoot = Field(default_factory=dict)-- @field_validator("root", mode="wrap")- @classmethod- def validate_concept_codes(- cls,- input_value: dict[str, InputRequirement],- handler: Callable[[dict[str, InputRequirement]], dict[str, InputRequirement]],- ) -> dict[str, InputRequirement]:- # First let Pydantic handle the basic type validation- validated_dict: dict[str, InputRequirement] = handler(input_value)-- # Now we can transform and validate the keys and values- transformed_dict: dict[str, InputRequirement] = {}- for required_input, requirement in validated_dict.items():- # in case of sub-attribute, the variable name is the object name, before the 1st dot- transformed_key: str = required_input.split(".", 1)[0]- if transformed_key != required_input:- log.verbose(f"Sub-attribute {required_input} detected, using {transformed_key} as variable name")-- if transformed_key in transformed_dict and transformed_dict[transformed_key] != requirement:- log.verbose(- f"Variable {transformed_key} already exists with a different concept code: {transformed_dict[transformed_key]} -> {requirement}",- )- transformed_dict[transformed_key] = InputRequirement(concept=requirement.concept, multiplicity=requirement.multiplicity)-- return transformed_dict-- def set_default_domain(self, domain: str):- for input_name, requirement in self.root.items():- input_concept_code = requirement.concept.code- if "." not in input_concept_code:- requirement.concept.code = f"{domain}.{input_concept_code}"- self.root[input_name] = requirement-- def get_required_input_requirement(self, variable_name: str) -> InputRequirement:- requirement = self.root.get(variable_name)- if not requirement:- msg = f"Variable '{variable_name}' not found the input requirements"- raise PipeInputNotFoundError(msg)- return requirement-- def is_variable_existing(self, variable_name: str) -> bool:- return variable_name in self.root-- def add_requirement(self, variable_name: str, concept: Concept, multiplicity: VariableMultiplicity | None = None):- self.root[variable_name] = InputRequirement(concept=concept, multiplicity=multiplicity)-- @property- def items(self) -> list[tuple[str, InputRequirement]]:- return list(self.root.items())-- @property- def concepts(self) -> list[Concept]:- all_concepts: list[Concept] = []- for requirement in self.root.values():- if requirement.concept.concept_string not in [c.concept_string for c in all_concepts]:- all_concepts.append(requirement.concept)- return all_concepts-- @property- def variables(self) -> list[str]:- return list(self.root.keys())-- @property- def required_names(self) -> list[str]:- the_required_names: list[str] = []- for requirement_expression in self.root:- required_variable_name = requirement_expression.split(".", 1)[0]- the_required_names.append(required_variable_name)- return the_required_names-- @property- def named_input_requirements(self) -> list[NamedInputRequirement]:- the_requirements: list[NamedInputRequirement] = []- for requirement_expression, requirement in self.root.items():- required_variable_name = requirement_expression.split(".", 1)[0]- the_requirements.append(- NamedInputRequirement(- variable_name=required_variable_name,- requirement_expression=requirement_expression,- concept=requirement.concept,- multiplicity=requirement.multiplicity,- ),- )- return the_requirements-- @property- def is_empty(self) -> bool:- return not bool(self.root)-- def _is_multiple(self, multiplicity: VariableMultiplicity | None) -> bool:- """Check if multiplicity indicates multiple items."""- if multiplicity is None:- return False- if isinstance(multiplicity, bool):- return multiplicity- return multiplicity > 1-- def generate_json_representation(self) -> dict[str, Any]:- """Generate a JSON representation for all inputs.-- Returns:- Dictionary with JSON representations for each input- """- json_inputs: dict[str, Any] = {}- for var_name, input_req in self.root.items():- is_multiple = self._is_multiple(input_req.multiplicity)- json_value, _ = input_req.concept.generate_input_representation(- output_format=ConceptRepresentationFormat.JSON,- is_multiple=is_multiple,- )- json_inputs[var_name] = json_value-- return json_inputs-- def generate_json_string(self, indent: int = 2) -> str:- """Generate a JSON representation for all inputs as a formatted string.-- Args:- indent: Number of spaces for indentation (default: 2)-- Returns:- Formatted JSON string- """- json_inputs = self.generate_json_representation()- return json.dumps(json_inputs, indent=indent, ensure_ascii=False)diff --git a/pipelex/core/pipes/inputs/input_stuff_specs.py b/pipelex/core/pipes/inputs/input_stuff_specs.pynew file mode 100644index 000000000..ca5ea82dc--- /dev/null+++ b/pipelex/core/pipes/inputs/input_stuff_specs.py@@ -0,0 +1,154 @@+import json+from collections.abc import Callable+from typing import Any++from pydantic import Field, RootModel, field_validator++from pipelex import log+from pipelex.core.concepts.concept import Concept+from pipelex.core.concepts.concept_representation_generator import ConceptRepresentationFormat+from pipelex.core.pipes.inputs.exceptions import InputStuffSpecNotFoundError+from pipelex.core.pipes.stuff_spec.stuff_spec import StuffSpec+from pipelex.core.pipes.variable_multiplicity import VariableMultiplicity+from pipelex.core.stuffs.stuff_content import StuffContent+++class NamedStuffSpec(StuffSpec):+ variable_name: str+ requirement_expression: str | None = None+++class TypedNamedStuffSpec(NamedStuffSpec):+ structure_class: type[StuffContent]++ @classmethod+ def make_from_named(+ cls,+ named: NamedStuffSpec,+ structure_class: type[StuffContent],+ ) -> "TypedNamedStuffSpec":+ return cls(**named.model_dump(), structure_class=structure_class)+++PipeInputsRoot = dict[str, StuffSpec]+++class InputStuffSpecs(RootModel[PipeInputsRoot]):+ root: PipeInputsRoot = Field(default_factory=dict)++ @field_validator("root", mode="wrap")+ @classmethod+ def validate_concept_codes(+ cls,+ input_value: PipeInputsRoot,+ handler: Callable[[PipeInputsRoot], PipeInputsRoot],+ ) -> PipeInputsRoot:+ # First let Pydantic handle the basic type validation+ stuff_specs: PipeInputsRoot = handler(input_value)++ # Now we can transform and validate the keys and values+ transformed_dict: PipeInputsRoot = {}+ for input_name, stuff_spec in stuff_specs.items():+ # in case of sub-attribute, the variable name is the object name, before the 1st dot+ transformed_key: str = input_name.split(".", 1)[0]+ if transformed_key != input_name:+ log.verbose(f"Sub-attribute {input_name} detected, using {transformed_key} as variable name")++ if transformed_key in transformed_dict and transformed_dict[transformed_key] != stuff_spec:+ log.verbose(+ f"Variable {transformed_key} already exists with a different concept code: {transformed_dict[transformed_key]} -> {stuff_spec}",+ )+ transformed_dict[transformed_key] = StuffSpec(concept=stuff_spec.concept, multiplicity=stuff_spec.multiplicity)++ return transformed_dict++ def set_default_domain(self, domain: str):+ for input_name, stuff_spec in self.root.items():+ input_concept_code = stuff_spec.concept.code+ if "." not in input_concept_code:+ stuff_spec.concept.code = f"{domain}.{input_concept_code}"+ self.root[input_name] = stuff_spec++ def get_required_stuff_spec(self, variable_name: str) -> StuffSpec:+ stuff_spec = self.root.get(variable_name)+ if not stuff_spec:+ msg = f"Variable '{variable_name}' not found the input stuff specs"+ raise InputStuffSpecNotFoundError(msg)+ return stuff_spec++ def is_variable_existing(self, variable_name: str) -> bool:+ return variable_name in self.root++ def add_stuff_spec(self, variable_name: str, concept: Concept, multiplicity: VariableMultiplicity | None = None):+ self.root[variable_name] = StuffSpec(concept=concept, multiplicity=multiplicity)++ @property+ def items(self) -> list[tuple[str, StuffSpec]]:+ return list(self.root.items())++ @property+ def concepts(self) -> list[Concept]:+ all_concepts: list[Concept] = []+ for stuff_spec in self.root.values():+ if stuff_spec.concept.concept_string not in [c.concept_string for c in all_concepts]:+ all_concepts.append(stuff_spec.concept)+ return all_concepts++ @property+ def variables(self) -> list[str]:+ return list(self.root.keys())++ @property+ def required_names(self) -> list[str]:+ the_required_names: list[str] = []+ for requirement_expression in self.root:+ required_variable_name = requirement_expression.split(".", 1)[0]+ the_required_names.append(required_variable_name)+ return the_required_names++ @property+ def named_stuff_specs(self) -> list[NamedStuffSpec]:+ the_named_stuff_spec: list[NamedStuffSpec] = []+ for requirement_expression, stuff_spec in self.root.items():+ required_variable_name = requirement_expression.split(".", 1)[0]+ the_named_stuff_spec.append(+ NamedStuffSpec(+ variable_name=required_variable_name,+ requirement_expression=requirement_expression,+ concept=stuff_spec.concept,+ multiplicity=stuff_spec.multiplicity,+ ),+ )+ return the_named_stuff_spec++ @property+ def is_empty(self) -> bool:+ return not bool(self.root)++ def generate_json_representation(self) -> dict[str, Any]:+ """Generate a JSON representation for all inputs.++ Returns:+ Dictionary with JSON representations for each input+ """+ json_inputs: dict[str, Any] = {}+ for var_name, stuff_spec in self.root.items():+ json_value, _ = stuff_spec.concept.generate_input_representation(+ output_format=ConceptRepresentationFormat.JSON,+ is_multiple=stuff_spec.is_multiple(),+ )+ json_inputs[var_name] = json_value++ return json_inputs++ def generate_json_string(self, indent: int = 2) -> str:+ """Generate a JSON representation for all inputs as a formatted string.++ Args:+ indent: Number of spaces for indentation (default: 2)++ Returns:+ Formatted JSON string+ """+ json_inputs = self.generate_json_representation()+ return json.dumps(json_inputs, indent=indent, ensure_ascii=False)diff --git a/pipelex/core/pipes/inputs/input_requirements_factory.py b/pipelex/core/pipes/inputs/input_stuff_specs_factory.pysimilarity index 62%rename from pipelex/core/pipes/inputs/input_requirements_factory.pyrename to pipelex/core/pipes/inputs/input_stuff_specs_factory.pyindex 8501cdde0..0856d5f95 100644--- a/pipelex/core/pipes/inputs/input_requirements_factory.py+++ b/pipelex/core/pipes/inputs/input_stuff_specs_factory.py@@ -5,44 +5,45 @@ from pipelex.base_exceptions import PipelexErrorfrom pipelex.core.concepts.concept_factory import ConceptFactoryfrom pipelex.core.concepts.exceptions import ConceptStringErrorfrom pipelex.core.concepts.validation import validate_concept_string_or_code-from pipelex.core.pipes.inputs.input_requirements import InputRequirement, InputRequirements+from pipelex.core.pipes.inputs.input_stuff_specs import InputStuffSpecs, PipeInputsRoot+from pipelex.core.pipes.stuff_spec.stuff_spec import StuffSpecfrom pipelex.hub import get_required_conceptif TYPE_CHECKING:from pipelex.core.pipes.variable_multiplicity import VariableMultiplicity-class InputRequirementsFactoryError(PipelexError):+class InputStuffSpecsFactoryError(PipelexError):pass-class InputRequirementsFactory:+class InputStuffSpecsFactory:@classmethod- def make_empty(cls) -> InputRequirements:- return InputRequirements(root={})+ def make_empty(cls) -> InputStuffSpecs:+ return InputStuffSpecs(root={})@classmethoddef make_from_blueprint(cls,domain: str,blueprint: dict[str, str],- ) -> InputRequirements:- input_requirements_dict: dict[str, InputRequirement] = {}- for var_name, requirement_str in blueprint.items():- input_requirement = InputRequirementsFactory.make_from_string(+ ) -> InputStuffSpecs:+ stuff_specs: PipeInputsRoot = {}+ for var_name, stuff_spec_str in blueprint.items():+ stuff_spec = InputStuffSpecsFactory.make_from_string(domain=domain,- requirement_str=requirement_str,+ stuff_spec_str=stuff_spec_str,)- input_requirements_dict[var_name] = input_requirement- return InputRequirements(root=input_requirements_dict)+ stuff_specs[var_name] = stuff_spec+ return InputStuffSpecs(root=stuff_specs)@classmethoddef make_from_string(cls,domain: str,- requirement_str: str,- ) -> InputRequirement:- """Parse an input requirement string and return an InputRequirement.+ stuff_spec_str: str,+ ) -> StuffSpec:+ """Parse an input requirement string and return an StuffSpec.Interprets multiplicity from a string in the form:- "domain.ConceptCode[5]" -> multiplicity = 5 (int)@@ -52,23 +53,23 @@ class InputRequirementsFactory:Args:domain: The domain to use for resolving concept codes without domain prefix- requirement_str: String in the format "domain.ConceptCode" or "ConceptCode" with optional "[multiplicity]"+ stuff_spec_str: String in the format "domain.ConceptCode" or "ConceptCode" with optional "[multiplicity]"Returns:- InputRequirement with the parsed concept and multiplicity+ StuffSpec with the parsed concept and multiplicityRaises:- InputRequirementsFactorySyInputRequirementsFactoryErrorntaxError: If the requirement string format is invalid+ InputStuffSpecsFactoryError: If the stuff spec string format is invalid"""# Pattern to match concept string and optional multiplicity brackets# Group 1: concept string (everything before brackets)# Group 2: content inside brackets (empty string for [], digits for [5])pattern = r"^(.+?)(?:\[(\d*)\])?$"- match = re.match(pattern, requirement_str)+ match = re.match(pattern, stuff_spec_str)if not match:- msg = f"Invalid input requirement string: {requirement_str}"- raise InputRequirementsFactoryError(msg)+ msg = f"Invalid input stuff spec string: {stuff_spec_str}"+ raise InputStuffSpecsFactoryError(msg)concept_string_or_code = match.group(1)multiplicity_str = match.group(2)@@ -77,8 +78,8 @@ class InputRequirementsFactory:try:validate_concept_string_or_code(concept_string_or_code=concept_string_or_code)except ConceptStringError as exc:- msg = f"Invalid concept string '{concept_string_or_code}' when trying to make an 'InputRequirement' from string: {exc}"- raise InputRequirementsFactoryError(msg) from exc+ msg = f"Invalid concept string '{concept_string_or_code}' when trying to make an 'StuffSpec' from string: {exc}"+ raise InputStuffSpecsFactoryError(msg) from excconcept_string_with_domain = ConceptFactory.make_concept_string_with_domain_from_concept_string_or_code(domain=domain,@@ -87,6 +88,7 @@ class InputRequirementsFactory:# Determine multiplicitymultiplicity: VariableMultiplicity | None = None+if multiplicity_str is not None: # Brackets were presentif multiplicity_str == "": # Empty brackets []multiplicity = True@@ -95,4 +97,4 @@ class InputRequirementsFactory:# else: No brackets, multiplicity stays Noneconcept = get_required_concept(concept_string=concept_string_with_domain)- return InputRequirement(concept=concept, multiplicity=multiplicity)+ return StuffSpec(concept=concept, multiplicity=multiplicity)diff --git a/pipelex/core/pipes/pipe_abstract.py b/pipelex/core/pipes/pipe_abstract.pyindex f2d1491a7..a01463d38 100644--- a/pipelex/core/pipes/pipe_abstract.py+++ b/pipelex/core/pipes/pipe_abstract.py@@ -11,9 +11,10 @@ from pipelex.core.concepts.native.concept_native import NativeConceptCodefrom pipelex.core.memory.working_memory import WorkingMemoryfrom pipelex.core.pipes.exceptions import PipeValidationError, PipeValidationErrorTypefrom pipelex.core.pipes.inputs.exceptions import PipeRunInputsError-from pipelex.core.pipes.inputs.input_requirements import InputRequirements+from pipelex.core.pipes.inputs.input_stuff_specs import InputStuffSpecsfrom pipelex.core.pipes.pipe_blueprint import PipeCategory, PipeTypefrom pipelex.core.pipes.pipe_output import PipeOutput+from pipelex.core.pipes.stuff_spec.stuff_spec import StuffSpecfrom pipelex.pipe_run.pipe_run_mode import PipeRunModefrom pipelex.pipe_run.pipe_run_params import PipeRunParamsfrom pipelex.pipeline.exceptions import PipeStackOverflowError@@ -41,8 +42,8 @@ class PipeAbstract(ABC, BaseModel):code: strdomain: strdescription: str | None = None- inputs: InputRequirements = Field(default_factory=InputRequirements)- output: Concept+ inputs: InputStuffSpecs = Field(default_factory=InputStuffSpecs)+ output: StuffSpec@propertydef pipe_type(self) -> str:@@ -55,8 +56,8 @@ class PipeAbstract(ABC, BaseModel):unique_concepts: list[Concept] = []# Add output concept first- unique_concepts.append(self.output)- seen_concept_strings.add(self.output.concept_string)+ unique_concepts.append(self.output.concept)+ seen_concept_strings.add(self.output.concept.concept_string)# Add input concepts (avoiding duplicates)for concept in self.inputs.concepts:@@ -144,9 +145,9 @@ class PipeAbstract(ABC, BaseModel):# Then validate that all inputs are actually needed and match requirements exactlythe_needed_inputs = self.needed_inputs()- # Check all required variables are in the inputs and match the required InputRequirement- for named_input_requirement in the_needed_inputs.named_input_requirements:- var_name = named_input_requirement.variable_name+ # Check all required variables are in the inputs and match the required StuffSpec+ for named_stuff_spec in the_needed_inputs.named_stuff_specs:+ var_name = named_stuff_spec.variable_nameif var_name not in self.inputs.variables:msg = f"Required variable '{var_name}' is not in the inputs of pipe '{self.code}'. Current inputs: {self.inputs}"@@ -160,35 +161,35 @@ class PipeAbstract(ABC, BaseModel):# TODO: add this to the PipeController validation. (This might need to refactor a little bit how we can override the validation)if PipeCategory.is_controller_by_str(self.pipe_category):- # Compare the essential parts of InputRequirement (concept code + multiplicity)- # Skip validation if the needed requirement is Dynamic or Anything (flexible output types)- declared_requirement = self.inputs.root[var_name]- needed_requirement = the_needed_inputs.root[named_input_requirement.requirement_expression or var_name]+ # Compare the essential parts of StuffSpec (concept code + multiplicity)+ # Skip validation if the needed stuff_spec is Dynamic or Anything (flexible output types)+ declared_stuff_spec = self.inputs.root[var_name]+ needed_stuff_spec = the_needed_inputs.root[named_stuff_spec.requirement_expression or var_name]- # Allow mismatch if the needed requirement is a flexible type (Dynamic or Anything)+ # Allow mismatch if the needed stuff_spec is a flexible type (Dynamic or Anything)if (- needed_requirement.concept.code not in {NativeConceptCode.DYNAMIC, NativeConceptCode.ANYTHING}- and declared_requirement != needed_requirement+ needed_stuff_spec.concept.code not in {NativeConceptCode.DYNAMIC, NativeConceptCode.ANYTHING}+ and declared_stuff_spec != needed_stuff_spec):# Identify the specific mismatched field(s)mismatch_details: list[str] = []- if declared_requirement.concept != needed_requirement.concept:- mismatch_details.append(f"concept: declared='{declared_requirement.concept}' vs required='{needed_requirement.concept}'")- if declared_requirement.multiplicity != needed_requirement.multiplicity:+ if declared_stuff_spec.concept != needed_stuff_spec.concept:+ mismatch_details.append(f"concept: declared='{declared_stuff_spec.concept}' vs required='{needed_stuff_spec.concept}'")+ if declared_stuff_spec.multiplicity != needed_stuff_spec.multiplicity:mismatch_details.append(- f"multiplicity: declared='{declared_requirement.multiplicity}' vs required='{needed_requirement.multiplicity}'"+ f"multiplicity: declared='{declared_stuff_spec.multiplicity}' vs required='{needed_stuff_spec.multiplicity}'")mismatch_summary = ", ".join(mismatch_details)msg = (- f"In the pipe '{self.code}', the input variable '{var_name}' has a requirement mismatch.\n"+ f"In the pipe '{self.code}', the input variable '{var_name}' has a stuff spec mismatch.\n"f"Mismatched field(s): {mismatch_summary}\n"- f"Declared: {declared_requirement}\n"- f"Required: {needed_requirement}"+ f"Declared: {declared_stuff_spec}\n"+ f"Required: {needed_stuff_spec}")raise PipeValidationError(message=msg,- error_type=PipeValidationErrorType.INPUT_REQUIREMENT_MISMATCH,+ error_type=PipeValidationErrorType.INPUT_STUFF_SPEC_MISMATCH,domain=self.domain,pipe_code=self.code,variable_names=[var_name],@@ -256,15 +257,15 @@ class PipeAbstract(ABC, BaseModel):"""@abstractmethod- def needed_inputs(self, visited_pipes: set[str] | None = None) -> InputRequirements:- """Return the inputs that are needed for the pipe to run.+ def needed_inputs(self, visited_pipes: set[str] | None = None) -> InputStuffSpecs:+ """Return the stuff specs that are needed for the pipe to run.Args:visited_pipes: Set of pipe codes currently being processed to prevent infinite recursion.If None, starts recursion detection with an empty set.Returns:- InputRequirements containing all needed inputs for this pipe+ InputStuffSpecs containing all needed inputs for this pipe"""@@ -287,7 +288,7 @@ class PipeAbstract(ABC, BaseModel):case PipeRunMode.DRY:pipe_type_label = f"[dim]Dry run:[/dim] {pipe_type_label}"pipe_code_label = f"[red]{self.code}[/red]"- concept_code_label = f"[bold green]{self.output.code}[/bold green]"+ concept_code_label = f"[bold green]{self.output.concept.code}[/bold green]"arrow = "[yellow]→[/yellow]"return f"{indent}{pipe_type_label} {pipe_code_label} {arrow} {concept_code_label}"@@ -490,12 +491,15 @@ class PipeAbstract(ABC, BaseModel):# check we have the required inputs in the working memorymissing_inputs: dict[str, str] = {}- for required_stuff_name, requirement in self.needed_inputs().items:+ for required_stuff_name, stuff_spec in self.needed_inputs().items:if not working_memory.is_stuff_exists(name=required_stuff_name):- missing_inputs[required_stuff_name] = requirement.concept.code+ missing_inputs[required_stuff_name] = stuff_spec.concept.codeif missing_inputs:error = PipeRunInputsError(- message=f"Missing required inputs for pipe '{self.code}': {missing_inputs}", pipe_code=self.code, missing_inputs=missing_inputs+ message=f"Missing required inputs for pipe '{self.code}': {missing_inputs}",+ run_mode=pipe_run_params.run_mode,+ pipe_code=self.code,+ missing_inputs=missing_inputs,)raise errordiff --git a/pipelex/core/pipes/pipe_factory.py b/pipelex/core/pipes/pipe_factory.pyindex c57e8b89b..cbbae5dbb 100644--- a/pipelex/core/pipes/pipe_factory.py+++ b/pipelex/core/pipes/pipe_factory.py@@ -4,17 +4,14 @@ from kajson.exceptions import ClassRegistryInheritanceError, ClassRegistryNotFoufrom kajson.kajson_manager import KajsonManagerfrom typing_extensions import runtime_checkable-from pipelex.core.concepts.concept import Concept-from pipelex.core.concepts.concept_factory import ConceptFactory-from pipelex.core.concepts.exceptions import ConceptFactoryErrorfrom pipelex.core.concepts.helpers import strip_multiplicity_from_concept_string_or_codefrom pipelex.core.concepts.native.concept_native import NativeConceptCode-from pipelex.core.pipes.exceptions import PipeFactoryError, PipeFactoryErrorType, PipeVariableMultiplicityError-from pipelex.core.pipes.inputs.input_requirements import InputRequirements-from pipelex.core.pipes.inputs.input_requirements_factory import InputRequirementsFactory+from pipelex.core.pipes.exceptions import PipeFactoryError, PipeFactoryErrorType+from pipelex.core.pipes.inputs.input_stuff_specs import InputStuffSpecs+from pipelex.core.pipes.inputs.input_stuff_specs_factory import InputStuffSpecsFactoryfrom pipelex.core.pipes.pipe_blueprint import PipeBlueprint, PipeType-from pipelex.core.pipes.variable_multiplicity import parse_concept_with_multiplicity-from pipelex.hub import get_required_concept+from pipelex.core.pipes.stuff_spec.stuff_spec import StuffSpec+from pipelex.core.pipes.stuff_spec.stuff_spec_factory import StuffSpecFactory, StuffSpecFactoryErrorif TYPE_CHECKING:from pipelex.core.pipes.pipe_abstract import PipeAbstract@@ -33,8 +30,8 @@ class PipeFactoryProtocol(Protocol[PipeBlueprintType, PipeAbstractType]):pipe_code: str,domain_code: str,description: str | None,- inputs: InputRequirements,- output: Concept,+ inputs: InputStuffSpecs,+ output: StuffSpec,blueprint: PipeBlueprintType,) -> PipeAbstractType: ...@@ -92,8 +89,12 @@ class PipeFactory(Generic[PipeAbstractType]):)# Parse common attributes- parsed_output = cls._parse_output_concept_string(domain=domain_code, pipe_code=pipe_code, output_string=blueprint.output)- parsed_inputs = InputRequirementsFactory.make_from_blueprint(+ try:+ parsed_output = StuffSpecFactory.make_from_blueprint(domain=domain_code, output_string=blueprint.output)+ except StuffSpecFactoryError as exc:+ msg = f"Error parsing output string '{blueprint.output}': {exc}"+ raise PipeFactoryError(msg) from exc+ parsed_inputs = InputStuffSpecsFactory.make_from_blueprint(domain=domain_code,blueprint=blueprint.inputs or {},)@@ -126,35 +127,3 @@ class PipeFactory(Generic[PipeAbstractType]):blueprint=blueprint,)return pipe-- @classmethod- def _parse_output_concept_string(- cls,- domain: str,- pipe_code: str,- output_string: str,- ) -> Concept:- """Parse the output concept string and return the Concept object."""- # Parse output to strip multiplicity brackets- try:- output_parse_result = parse_concept_with_multiplicity(output_string)- except PipeVariableMultiplicityError as exc:- msg = f"Error parsing concept with multiplicity for pipe '{pipe_code}': {exc}"- raise PipeFactoryError(msg) from exc-- # Get output concept- try:- output_domain_and_code = ConceptFactory.make_domain_and_concept_code_from_concept_string_or_code(- domain=domain,- concept_string_or_code=output_parse_result.concept,- )- except ConceptFactoryError as exc:- msg = f"Error making domain and concept code for pipe '{pipe_code}': {exc}"- raise PipeFactoryError(msg) from exc-- return get_required_concept(- concept_string=ConceptFactory.make_concept_string_with_domain(- domain=output_domain_and_code.domain,- concept_code=output_domain_and_code.concept_code,- ),- )diff --git a/pipelex/core/pipes/stuff_spec/__init__.py b/pipelex/core/pipes/stuff_spec/__init__.pynew file mode 100644index 000000000..e69de29bbdiff --git a/pipelex/core/pipes/stuff_spec/exceptions.py b/pipelex/core/pipes/stuff_spec/exceptions.pynew file mode 100644index 000000000..60b898ad6--- /dev/null+++ b/pipelex/core/pipes/stuff_spec/exceptions.py@@ -0,0 +1,12 @@+from pipelex.base_exceptions import PipelexError+++class StuffSpecError(PipelexError):+ def __init__(self, message: str, pipe_code: str, missing_inputs: dict[str, str]):+ self.pipe_code = pipe_code+ self.missing_inputs = missing_inputs+ super().__init__(message)+++class PipeInputsFactoryError(PipelexError):+ passdiff --git a/pipelex/core/pipes/stuff_spec/stuff_spec.py b/pipelex/core/pipes/stuff_spec/stuff_spec.pynew file mode 100644index 000000000..657004f60--- /dev/null+++ b/pipelex/core/pipes/stuff_spec/stuff_spec.py@@ -0,0 +1,16 @@+from pydantic import BaseModel++from pipelex.core.concepts.concept import Concept+from pipelex.core.pipes.variable_multiplicity import VariableMultiplicity+++class StuffSpec(BaseModel):+ concept: Concept+ multiplicity: VariableMultiplicity | None = None++ def is_multiple(self) -> bool:+ if self.multiplicity is None:+ return False+ if isinstance(self.multiplicity, bool):+ return self.multiplicity+ return self.multiplicity > 1diff --git a/pipelex/core/pipes/stuff_spec/stuff_spec_factory.py b/pipelex/core/pipes/stuff_spec/stuff_spec_factory.pynew file mode 100644index 000000000..37f81c72b--- /dev/null+++ b/pipelex/core/pipes/stuff_spec/stuff_spec_factory.py@@ -0,0 +1,58 @@+from pipelex.base_exceptions import PipelexError+from pipelex.core.concepts.concept_factory import ConceptFactory+from pipelex.core.concepts.exceptions import ConceptFactoryError+from pipelex.core.pipes.exceptions import PipeVariableMultiplicityError+from pipelex.core.pipes.stuff_spec.stuff_spec import StuffSpec+from pipelex.core.pipes.variable_multiplicity import parse_concept_with_multiplicity+from pipelex.hub import get_required_concept+++class StuffSpecFactoryError(PipelexError):+ pass+++class StuffSpecFactory:+ @classmethod+ def make_from_blueprint(+ cls,+ domain: str,+ output_string: str,+ ) -> StuffSpec:+ """Parse an output string and return a StuffSpec with concept and multiplicity.++ Args:+ domain: The domain to use for resolving concept codes without domain prefix+ output_string: String in the format "ConceptCode" or "domain.ConceptCode"+ with optional "[multiplicity]" (e.g., "Text", "Text[]", "Text[3]")++ Returns:+ StuffSpec with the parsed concept and multiplicity++ Raises:+ StuffSpecFactoryError: If the output string format is invalid+ """+ # Parse output to extract concept and multiplicity+ try:+ parse_result = parse_concept_with_multiplicity(output_string)+ except PipeVariableMultiplicityError as exc:+ msg = f"Error parsing output string '{output_string}': {exc}"+ raise StuffSpecFactoryError(msg) from exc++ # Resolve concept with domain+ try:+ domain_and_code = ConceptFactory.make_domain_and_concept_code_from_concept_string_or_code(+ domain=domain,+ concept_string_or_code=parse_result.concept,+ )+ except ConceptFactoryError as exc:+ msg = f"Error resolving concept from output string '{output_string}': {exc}"+ raise StuffSpecFactoryError(msg) from exc++ concept = get_required_concept(+ concept_string=ConceptFactory.make_concept_string_with_domain(+ domain=domain_and_code.domain,+ concept_code=domain_and_code.concept_code,+ ),+ )++ return StuffSpec(concept=concept, multiplicity=parse_result.multiplicity)diff --git a/pipelex/core/pipes/variable_multiplicity.py b/pipelex/core/pipes/variable_multiplicity.pyindex b9d6ff3e1..ba466e93a 100644--- a/pipelex/core/pipes/variable_multiplicity.py+++ b/pipelex/core/pipes/variable_multiplicity.py@@ -76,7 +76,8 @@ def parse_concept_with_multiplicity(concept_spec: str) -> MultiplicityParseResulMultiplicityParseResult with concept (without brackets) and multiplicity valueRaises:- ValueError: If the concept specification has invalid syntax+ PipeVariableMultiplicityError: If the concept specification has invalid syntax+ or if multiplicity is zero or negative (a pipe must produce at least one output)"""# Use strict pattern to validate identifier syntax# Concept must start with letter/underscore, optional domain prefix, optional brackets@@ -105,6 +106,9 @@ def parse_concept_with_multiplicity(concept_spec: str) -> MultiplicityParseResulelse:# Number in brackets [N] - fixed countmultiplicity = int(bracket_content)+ if multiplicity <= 0:+ msg = f"Invalid multiplicity value in '{concept_spec}': multiplicity must be at least 1. A pipe must produce at least one output."+ raise PipeVariableMultiplicityError(msg)return MultiplicityParseResult(concept=concept, multiplicity=multiplicity)diff --git a/pipelex/exceptions.py b/pipelex/exceptions.pyindex 2323d8358..99dadd92d 100644--- a/pipelex/exceptions.py+++ b/pipelex/exceptions.py@@ -22,7 +22,7 @@ from pipelex.core.pipes.exceptions import (PipeOperatorModelChoiceError,PipeValidationError,)-from pipelex.core.pipes.inputs.exceptions import PipeInputNotFoundError+from pipelex.core.pipes.inputs.exceptions import InputStuffSpecNotFoundErrorfrom pipelex.core.stuffs.exceptions import (StuffArtefactError,StuffArtefactReservedFieldError,@@ -91,7 +91,7 @@ __all__ = ["PipeRouterError","PipeRunError",# from pipelex.core.pipes.exceptions- "PipeInputNotFoundError",+ "InputStuffSpecNotFoundError","PipeFactoryError","PipeOperatorModelChoiceError",# from pipelex.core.stuffs.exceptionsdiff --git a/pipelex/libraries/exceptions.py b/pipelex/libraries/exceptions.pyindex b1090c632..268b7f0c1 100644--- a/pipelex/libraries/exceptions.py+++ b/pipelex/libraries/exceptions.py@@ -17,7 +17,7 @@ class LibraryLoadingError(LibraryError):2. Pipe/Concept validation errors (from Pipe or Concept class validation)- Stored in: pipe_concept_validation_errors- - Example: MISSING_INPUT_VARIABLE, INPUT_REQUIREMENT_MISMATCH+ - Example: MISSING_INPUT_VARIABLE, INPUT_STUFF_SPEC_MISMATCHAlso handles:- Factory errors (Domain, Concept, Pipe)diff --git a/pipelex/libraries/pipe/pipe_library.py b/pipelex/libraries/pipe/pipe_library.pyindex 53b8d953e..c0f75cbe9 100644--- a/pipelex/libraries/pipe/pipe_library.py+++ b/pipelex/libraries/pipe/pipe_library.py@@ -118,9 +118,9 @@ class PipeLibrary(RootModel[PipeLibraryRoot], PipeLibraryAbstract):for pipe in domain_pipes:inputs = pipe.inputs- formatted_inputs = [f"{name}: {_format_concept_code(requirement.concept.code, domain)}" for name, requirement in inputs.items]+ formatted_inputs = [f"{name}: {_format_concept_code(stuff_spec.concept.code, domain)}" for name, stuff_spec in inputs.items]formatted_inputs_str = ", ".join(formatted_inputs)- output_code = _format_concept_code(pipe.output.code, domain)+ output_code = _format_concept_code(pipe.output.concept.code, domain)table.add_row(pipe.code,@@ -132,7 +132,7 @@ class PipeLibrary(RootModel[PipeLibraryRoot], PipeLibraryAbstract):pipes_dict[domain][pipe.code] = {"description": pipe.description or "","inputs": formatted_inputs_str,- "output": pipe.output.code,+ "output": pipe.output.concept.code,}pretty_print(table)diff --git a/pipelex/pipe_controllers/batch/pipe_batch.py b/pipelex/pipe_controllers/batch/pipe_batch.pyindex da477ee9d..8e4fe226f 100644--- a/pipelex/pipe_controllers/batch/pipe_batch.py+++ b/pipelex/pipe_controllers/batch/pipe_batch.py@@ -6,7 +6,7 @@ from typing_extensions import overridefrom pipelex.config import get_configfrom pipelex.core.memory.working_memory import MAIN_STUFF_NAME, WorkingMemory-from pipelex.core.pipes.inputs.input_requirements import InputRequirements+from pipelex.core.pipes.inputs.input_stuff_specs import InputStuffSpecsfrom pipelex.core.pipes.pipe_output import PipeOutputfrom pipelex.core.stuffs.list_content import ListContentfrom pipelex.core.stuffs.stuff_factory import StuffFactory@@ -44,7 +44,7 @@ class PipeBatch(PipeController):return required_variables@override- def needed_inputs(self, visited_pipes: set[str] | None = None) -> InputRequirements:+ def needed_inputs(self, visited_pipes: set[str] | None = None) -> InputStuffSpecs:return self.inputs@override@@ -79,11 +79,11 @@ class PipeBatch(PipeController):input_list_stuff_name = batch_params.input_list_stuff_nameif not self.inputs.is_variable_existing(variable_name=input_list_stuff_name):msg = f"Batch input list named '{input_list_stuff_name}' is not in PipeBatch '{self.code}' input requirements: {self.inputs}"- raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode)+ raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode, pipe_code=self.code)if not working_memory.is_stuff_exists(input_list_stuff_name):msg = f"Input list stuff '{input_list_stuff_name}' required by this PipeBatch '{self.code}' not found in working memory"- raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode)+ raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode, pipe_code=self.code)input_stuff = working_memory.get_stuff(input_list_stuff_name)if not isinstance(input_stuff.content, ListContent):@@ -91,7 +91,7 @@ class PipeBatch(PipeController):f"Input list stuff '{input_list_stuff_name}' of PipeBatch '{self.code}' must be ListContent, "f"got {input_stuff.stuff_name or 'unnamed'} = {type(input_stuff.content)}. stuff: {input_stuff}")- raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode)+ raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode, pipe_code=self.code)async def _run_batch_pipe(self,@@ -131,7 +131,7 @@ class PipeBatch(PipeController):branch_input_item_code = f"{input_stuff.stuff_code}-branch-{branch_index}"item_input_stuff = StuffFactory.make_stuff(code=branch_input_item_code,- concept=self.inputs.get_required_input_requirement(input_list_stuff_name).concept,+ concept=self.inputs.get_required_stuff_spec(input_list_stuff_name).concept,content=item,name=input_item_stuff_name,)@@ -176,7 +176,7 @@ class PipeBatch(PipeController):list_content: ListContent[StuffContent] = ListContent(items=output_items)output_stuff = StuffFactory.make_stuff(code=output_stuff_code,- concept=self.output,+ concept=self.output.concept,content=list_content,name=output_name,)diff --git a/pipelex/pipe_controllers/batch/pipe_batch_factory.py b/pipelex/pipe_controllers/batch/pipe_batch_factory.pyindex 718885d75..28fb8b7e2 100644--- a/pipelex/pipe_controllers/batch/pipe_batch_factory.py+++ b/pipelex/pipe_controllers/batch/pipe_batch_factory.py@@ -2,9 +2,9 @@ from typing import Anyfrom typing_extensions import override-from pipelex.core.concepts.concept import Concept-from pipelex.core.pipes.inputs.input_requirements import InputRequirements+from pipelex.core.pipes.inputs.input_stuff_specs import InputStuffSpecsfrom pipelex.core.pipes.pipe_factory import PipeFactoryProtocol+from pipelex.core.pipes.stuff_spec.stuff_spec import StuffSpecfrom pipelex.pipe_controllers.batch.pipe_batch import PipeBatchfrom pipelex.pipe_controllers.batch.pipe_batch_blueprint import PipeBatchBlueprintfrom pipelex.pipe_run.pipe_run_params import BatchParams@@ -20,8 +20,8 @@ class PipeBatchFactory(PipeFactoryProtocol[PipeBatchBlueprint, PipeBatch]):pipe_code: str,domain_code: str,description: str | None,- inputs: InputRequirements,- output: Concept,+ inputs: InputStuffSpecs,+ output: StuffSpec,blueprint: PipeBatchBlueprint,) -> PipeBatch:batch_params = BatchParams.make_batch_params(diff --git a/pipelex/pipe_controllers/condition/pipe_condition.py b/pipelex/pipe_controllers/condition/pipe_condition.pyindex bcebbe029..512ec2169 100644--- a/pipelex/pipe_controllers/condition/pipe_condition.py+++ b/pipelex/pipe_controllers/condition/pipe_condition.py@@ -10,8 +10,8 @@ from pipelex.core.concepts.native.concept_native import NativeConceptCodefrom pipelex.core.memory.exceptions import WorkingMemoryStuffNotFoundErrorfrom pipelex.core.memory.working_memory import WorkingMemoryfrom pipelex.core.pipes.exceptions import PipeValidationError, PipeValidationErrorType-from pipelex.core.pipes.inputs.input_requirements import InputRequirements-from pipelex.core.pipes.inputs.input_requirements_factory import InputRequirementsFactory+from pipelex.core.pipes.inputs.input_stuff_specs import InputStuffSpecs+from pipelex.core.pipes.inputs.input_stuff_specs_factory import InputStuffSpecsFactoryfrom pipelex.core.pipes.pipe_output import PipeOutputfrom pipelex.hub import get_content_generator, get_optional_pipe, get_pipe_router, get_pipeline_tracker, get_required_pipefrom pipelex.pipe_controllers.condition.pipe_condition_details import PipeConditionDetails@@ -71,18 +71,18 @@ class PipeCondition(PipeController):return required_variables@override- def needed_inputs(self, visited_pipes: set[str] | None = None) -> InputRequirements:+ def needed_inputs(self, visited_pipes: set[str] | None = None) -> InputStuffSpecs:if visited_pipes is None:visited_pipes = set()# If we've already visited this pipe, stop recursionif self.code in visited_pipes:- return InputRequirementsFactory.make_empty()+ return InputStuffSpecsFactory.make_empty()# Add this pipe to visited set for recursive callsvisited_pipes_with_current = visited_pipes | {self.code}- needed_inputs = InputRequirementsFactory.make_empty()+ needed_inputs = InputStuffSpecsFactory.make_empty()# 1. Add the variables from the expression/expression_templaterequired_variables = detect_jinja2_required_variables(@@ -94,7 +94,7 @@ class PipeCondition(PipeController):if not var_name.startswith("_"): # exclude internal variables starting with `_`# We don't know the concept code from just the variable name,# so we'll use a generic placeholder that will be validated later- needed_inputs.add_requirement(+ needed_inputs.add_stuff_spec(variable_name=var_name,concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.ANYTHING,@@ -107,8 +107,8 @@ class PipeCondition(PipeController):# Use the centralized recursion detectionpipe_needed_inputs = pipe.needed_inputs(visited_pipes_with_current)- for input_name, requirement in pipe_needed_inputs.items:- needed_inputs.add_requirement(variable_name=input_name, concept=requirement.concept)+ for input_name, stuff_spec in pipe_needed_inputs.items:+ needed_inputs.add_stuff_spec(variable_name=input_name, concept=stuff_spec.concept)return needed_inputs@override@@ -130,22 +130,22 @@ class PipeCondition(PipeController):"""for pipe_code in self.mapped_pipe_codes:pipe = get_required_pipe(pipe_code=pipe_code)- if self.output.concept_string not in {- pipe.output.concept_string,+ if self.output.concept.concept_string not in {+ pipe.output.concept.concept_string,NativeConceptCode.DYNAMIC.concept_string,NativeConceptCode.ANYTHING.concept_string,}:msg = (- f"The output concept code '{self.output.concept_string}' of the pipe '{self.code}' is not "- f"matching the output concept code '{pipe.output.concept_string}' of the pipe '{pipe_code}'"+ f"The output concept code '{self.output.concept.concept_string}' of the pipe '{self.code}' is not "+ f"matching the output concept code '{pipe.output.concept.concept_string}' of the pipe '{pipe_code}'")raise PipeValidationError(message=msg,error_type=PipeValidationErrorType.INADEQUATE_OUTPUT_CONCEPT,domain=self.domain,pipe_code=self.code,- provided_concept_code=pipe.output.concept_string,- required_concept_codes=[self.output.concept_string],+ provided_concept_code=pipe.output.concept.concept_string,+ required_concept_codes=[self.output.concept.concept_string],)# TODO: Restore this validation. The problem lies with needed_inputs that construct Anything concepts.@@ -204,7 +204,7 @@ class PipeCondition(PipeController):pipe_run_params: PipeRunParams,output_name: str | None = None,) -> PipeOutput:- log.verbose(f"{self.class_name} generating a '{self.output.code}'")+ log.verbose(f"{self.class_name} generating a '{self.output.concept.code}'")# TODO: restore pipe_layer feature# pipe_run_params.push_pipe_code(pipe_code=pipe_code)@@ -221,7 +221,7 @@ class PipeCondition(PipeController):if SpecialOutcome.is_fail(outcome):msg = f"PipeCondition '{self.code}' failed with outcome: {outcome}. Evaluated expression: {evaluated_expression}"- raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode)+ raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode, pipe_code=self.code)chosen_pipe = get_required_pipe(pipe_code=outcome)@@ -241,7 +241,7 @@ class PipeCondition(PipeController):pipe_condition_path_str = ".".join(pipe_condition_path)error_details = f"PipeCondition '{pipe_condition_path_str}', required_variables: {required_variables}, missing: '{exc.variable_name}'"msg = f"Some required stuff(s) not found: {error_details}"- raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode) from exc+ raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode, pipe_code=self.code) from exc# Track condition stepsfor required_stuff in required_stuffs:@@ -290,15 +290,16 @@ class PipeCondition(PipeController):needed_inputs = self.needed_inputs()missing_input_names: list[str] = []- for named_input_requirement in needed_inputs.named_input_requirements:- if not working_memory.get_optional_stuff(named_input_requirement.variable_name):- missing_input_names.append(named_input_requirement.variable_name)+ for named_stuff_spec in needed_inputs.named_stuff_specs:+ if not working_memory.get_optional_stuff(named_stuff_spec.variable_name):+ missing_input_names.append(named_stuff_spec.variable_name)if missing_input_names:log.error(f"Dry run failed: missing required inputs: {missing_input_names}")raise PipeRunError(message=f"Dry run failed for pipe '{self.code}' (PipeCondition): missing required inputs: {', '.join(missing_input_names)}",run_mode=pipe_run_params.run_mode,+ pipe_code=self.code,)# 2. Validate that the expression template is valid@@ -314,7 +315,7 @@ class PipeCondition(PipeController):f"Dry run failed for pipe '{self.code}' (PipeCondition): could not detect required variables "f"from expression template: {exc}\nTemplate:\n'{self.expression}'")- raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode) from exc+ raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode, pipe_code=self.code) from exc# 3. Validate that all values in the outcomes map (appart from special outcomes) do exist as pipe codesall_pipe_codes = set(self.outcome_map.values())@@ -329,7 +330,7 @@ class PipeCondition(PipeController):f"Dry run failed for PipeCondition '{self.code}': missing pipes: {', '.join(missing_pipes)}. "f"Pipe map: {self.outcome_map}, default: {self.default_outcome}")- raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode)+ raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode, pipe_code=self.code)# Here, it should launch the dry run of all the pipes in the outcomes mapfor pipe_code in self.mapped_pipe_codes:diff --git a/pipelex/pipe_controllers/condition/pipe_condition_factory.py b/pipelex/pipe_controllers/condition/pipe_condition_factory.pyindex f6a7a656b..3e562c0bb 100644--- a/pipelex/pipe_controllers/condition/pipe_condition_factory.py+++ b/pipelex/pipe_controllers/condition/pipe_condition_factory.py@@ -2,9 +2,9 @@ from typing import Anyfrom typing_extensions import override-from pipelex.core.concepts.concept import Concept-from pipelex.core.pipes.inputs.input_requirements import InputRequirements+from pipelex.core.pipes.inputs.input_stuff_specs import InputStuffSpecsfrom pipelex.core.pipes.pipe_factory import PipeFactoryProtocol+from pipelex.core.pipes.stuff_spec.stuff_spec import StuffSpecfrom pipelex.pipe_controllers.condition.exceptions import PipeConditionFactoryErrorfrom pipelex.pipe_controllers.condition.pipe_condition import PipeConditionfrom pipelex.pipe_controllers.condition.pipe_condition_blueprint import PipeConditionBlueprint@@ -20,8 +20,8 @@ class PipeConditionFactory(PipeFactoryProtocol[PipeConditionBlueprint, PipeCondipipe_code: str,domain_code: str,description: str | None,- inputs: InputRequirements,- output: Concept,+ inputs: InputStuffSpecs,+ output: StuffSpec,blueprint: PipeConditionBlueprint,) -> PipeCondition:# Compute expression from expression_template or expression in blueprintdiff --git a/pipelex/pipe_controllers/parallel/pipe_parallel.py b/pipelex/pipe_controllers/parallel/pipe_parallel.pyindex e31fa1022..27d7cd45c 100644--- a/pipelex/pipe_controllers/parallel/pipe_parallel.py+++ b/pipelex/pipe_controllers/parallel/pipe_parallel.py@@ -8,9 +8,9 @@ from pipelex import logfrom pipelex.core.concepts.concept import Conceptfrom pipelex.core.memory.working_memory import WorkingMemoryfrom pipelex.core.pipes.exceptions import PipeValidationError-from pipelex.core.pipes.inputs.exceptions import PipeInputNotFoundError-from pipelex.core.pipes.inputs.input_requirements import InputRequirements-from pipelex.core.pipes.inputs.input_requirements_factory import InputRequirementsFactory+from pipelex.core.pipes.inputs.exceptions import InputStuffSpecNotFoundError+from pipelex.core.pipes.inputs.input_stuff_specs import InputStuffSpecs+from pipelex.core.pipes.inputs.input_stuff_specs_factory import InputStuffSpecsFactoryfrom pipelex.core.pipes.pipe_output import PipeOutputfrom pipelex.core.stuffs.stuff_factory import StuffFactoryfrom pipelex.hub import get_pipeline_tracker, get_required_pipe@@ -59,18 +59,18 @@ class PipeParallel(PipeController):return set()@override- def needed_inputs(self, visited_pipes: set[str] | None = None) -> InputRequirements:+ def needed_inputs(self, visited_pipes: set[str] | None = None) -> InputStuffSpecs:if visited_pipes is None:visited_pipes = set()# If we've already visited this pipe, stop recursionif self.code in visited_pipes:- return InputRequirementsFactory.make_empty()+ return InputStuffSpecsFactory.make_empty()# Add this pipe to visited set for recursive callsvisited_pipes_with_current = visited_pipes | {self.code}- needed_inputs = InputRequirementsFactory.make_empty()+ needed_inputs = InputStuffSpecsFactory.make_empty()for sub_pipe in self.parallel_sub_pipes:pipe = get_required_pipe(pipe_code=sub_pipe.pipe_code)@@ -78,24 +78,24 @@ class PipeParallel(PipeController):pipe_needed_inputs = pipe.needed_inputs(visited_pipes_with_current)if sub_pipe.batch_params:try:- requirement = pipe_needed_inputs.get_required_input_requirement(variable_name=sub_pipe.batch_params.input_item_stuff_name)- except PipeInputNotFoundError as exc:+ stuff_spec = pipe_needed_inputs.get_required_stuff_spec(variable_name=sub_pipe.batch_params.input_item_stuff_name)+ except InputStuffSpecNotFoundError as exc:msg = (f"Batch input item named '{sub_pipe.batch_params.input_item_stuff_name}' is not "f"in this Parallel Pipe '{self.code}' input requirements: {pipe_needed_inputs}")raise PipeValidationError(message=msg) from exc- needed_inputs.add_requirement(+ needed_inputs.add_stuff_spec(variable_name=sub_pipe.batch_params.input_list_stuff_name,- concept=requirement.concept,+ concept=stuff_spec.concept,multiplicity=True,)- for input_name, requirement in pipe_needed_inputs.items:+ for input_name, stuff_spec in pipe_needed_inputs.items:if input_name != sub_pipe.batch_params.input_item_stuff_name:- needed_inputs.add_requirement(input_name, requirement.concept, requirement.multiplicity)+ needed_inputs.add_stuff_spec(input_name, stuff_spec.concept, stuff_spec.multiplicity)else:- for input_name, requirement in pipe_needed_inputs.items:- needed_inputs.add_requirement(input_name, requirement.concept, requirement.multiplicity)+ for input_name, stuff_spec in pipe_needed_inputs.items:+ needed_inputs.add_stuff_spec(input_name, stuff_spec.concept, stuff_spec.multiplicity)return needed_inputs@model_validator(mode="after")@@ -163,19 +163,19 @@ class PipeParallel(PipeController):sub_pipe_output_name = self.parallel_sub_pipes[output_index].output_nameif not sub_pipe_output_name:msg = "PipeParallel requires a result specified for each parallel sub pipe"- raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode)+ raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode, pipe_code=self.code)if self.add_each_output:working_memory.add_new_stuff(name=sub_pipe_output_name, stuff=output_stuff)output_stuff_content_items.append(output_stuff.content)if sub_pipe_output_name in output_stuffs:# TODO: check that at the blueprint / factory levelmsg = f"PipeParallel requires unique output names for each parallel sub pipe, but {sub_pipe_output_name} is already used"- raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode)+ raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode, pipe_code=self.code)output_stuffs[sub_pipe_output_name] = output_stuffif sub_pipe_output_name in output_stuff_contents:# TODO: check that at the blueprint / factory levelmsg = f"PipeParallel requires unique output names for each parallel sub pipe, but {sub_pipe_output_name} is already used"- raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode)+ raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode, pipe_code=self.code)output_stuff_contents[sub_pipe_output_name] = output_stuff.contentlog.verbose(f"PipeParallel '{self.code}': output_stuff_contents[{sub_pipe_output_name}]: {output_stuff_contents[sub_pipe_output_name]}")@@ -215,18 +215,18 @@ class PipeParallel(PipeController):log.verbose(f"PipeParallel: dry run controller pipe: {self.code}")if pipe_run_params.run_mode != PipeRunMode.DRY:msg = f"PipeSequence._dry_run_controller_pipe() called with run_mode = {pipe_run_params.run_mode} in pipe {self.code}"- raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode)+ raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode, pipe_code=self.code)# 1. Validate that all required inputs are present in the working memoryneeded_inputs = self.needed_inputs()missing_input_names: list[str] = []- for named_input_requirement in needed_inputs.named_input_requirements:- if not working_memory.get_optional_stuff(named_input_requirement.variable_name):- missing_input_names.append(named_input_requirement.variable_name)+ for named_stuff_spec in needed_inputs.named_stuff_specs:+ if not working_memory.get_optional_stuff(named_stuff_spec.variable_name):+ missing_input_names.append(named_stuff_spec.variable_name)if missing_input_names:msg = f"Dry run failed for pipe '{self.code}' (PipeParallel): missing required inputs: {missing_input_names}"- raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode)+ raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode, pipe_code=self.code)# 2. Validate that all sub-pipes existfor sub_pipe in self.parallel_sub_pipes:@@ -234,7 +234,7 @@ class PipeParallel(PipeController):get_required_pipe(pipe_code=sub_pipe.pipe_code)except PipeNotFoundError as exc:msg = f"Dry run failed for pipe '{self.code}' (PipeParallel): sub-pipe '{sub_pipe.pipe_code}' not found"- raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode) from exc+ raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode, pipe_code=self.code) from exc# 3. Run all sub-pipes in dry modetasks: list[Coroutine[Any, Any, PipeOutput]] = []@@ -261,7 +261,7 @@ class PipeParallel(PipeController):if not sub_pipe_output_name:sub_pipe_code = self.parallel_sub_pipes[output_index].pipe_codemsg = f"Dry run failed for pipe '{self.code}' (PipeParallel): sub-pipe '{sub_pipe_code}' output name not specified"- raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode)+ raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode, pipe_code=self.code)if self.add_each_output:working_memory.add_new_stuff(name=sub_pipe_output_name, stuff=output_stuff)@@ -271,7 +271,7 @@ class PipeParallel(PipeController):msg = (f"Dry run failed for pipe '{self.code}' (PipeParallel): sub-pipe '{sub_pipe_code}' duplicate output name '{sub_pipe_output_name}'")- raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode)+ raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode, pipe_code=self.code)output_stuffs[sub_pipe_output_name] = output_stuffoutput_stuff_contents[sub_pipe_output_name] = output_stuff.contentdiff --git a/pipelex/pipe_controllers/parallel/pipe_parallel_factory.py b/pipelex/pipe_controllers/parallel/pipe_parallel_factory.pyindex 6236e6676..e71951278 100644--- a/pipelex/pipe_controllers/parallel/pipe_parallel_factory.py+++ b/pipelex/pipe_controllers/parallel/pipe_parallel_factory.py@@ -2,10 +2,10 @@ from typing import TYPE_CHECKING, Anyfrom typing_extensions import override-from pipelex.core.concepts.concept import Conceptfrom pipelex.core.concepts.concept_factory import ConceptFactory-from pipelex.core.pipes.inputs.input_requirements import InputRequirements+from pipelex.core.pipes.inputs.input_stuff_specs import InputStuffSpecsfrom pipelex.core.pipes.pipe_factory import PipeFactoryProtocol+from pipelex.core.pipes.stuff_spec.stuff_spec import StuffSpecfrom pipelex.hub import get_required_conceptfrom pipelex.pipe_controllers.parallel.exceptions import PipeParallelFactoryErrorfrom pipelex.pipe_controllers.parallel.pipe_parallel import PipeParallel@@ -26,8 +26,8 @@ class PipeParallelFactory(PipeFactoryProtocol[PipeParallelBlueprint, PipeParallepipe_code: str,domain_code: str,description: str | None,- inputs: InputRequirements,- output: Concept,+ inputs: InputStuffSpecs,+ output: StuffSpec,blueprint: PipeParallelBlueprint,) -> PipeParallel:parallel_sub_pipes: list[SubPipe] = []diff --git a/pipelex/pipe_controllers/sequence/pipe_sequence.py b/pipelex/pipe_controllers/sequence/pipe_sequence.pyindex 677ee0844..6e23ed69f 100644--- a/pipelex/pipe_controllers/sequence/pipe_sequence.py+++ b/pipelex/pipe_controllers/sequence/pipe_sequence.py@@ -5,9 +5,9 @@ from typing_extensions import overridefrom pipelex.core.memory.working_memory import WorkingMemoryfrom pipelex.core.pipes.exceptions import PipeValidationError, PipeValidationErrorType-from pipelex.core.pipes.inputs.exceptions import PipeInputNotFoundError-from pipelex.core.pipes.inputs.input_requirements import InputRequirements-from pipelex.core.pipes.inputs.input_requirements_factory import InputRequirementsFactory+from pipelex.core.pipes.inputs.exceptions import InputStuffSpecNotFoundError+from pipelex.core.pipes.inputs.input_stuff_specs import InputStuffSpecs+from pipelex.core.pipes.inputs.input_stuff_specs_factory import InputStuffSpecsFactoryfrom pipelex.core.pipes.pipe_output import PipeOutputfrom pipelex.hub import get_concept_library, get_required_pipefrom pipelex.pipe_controllers.exceptions import PipeControllerOutputConceptMismatchError@@ -51,39 +51,59 @@ class PipeSequence(PipeController):@overridedef validate_output_with_library(self):"""Validate the output for the pipe sequence.- The output of the pipe sequence should match the output of the last step.++ The output of the pipe sequence should match the output of the last step,+ both in terms of concept compatibility and multiplicity."""last_step_pipe_code = self.sequential_sub_pipes[-1].pipe_codelast_step_pipe = get_required_pipe(pipe_code=last_step_pipe_code)- last_step_output_concept = last_step_pipe.output- if not get_concept_library().is_compatible(tested_concept=last_step_output_concept, wanted_concept=self.output):+ last_step_stuff_spec = last_step_pipe.output++ # Check concept compatibility+ if not get_concept_library().is_compatible(tested_concept=last_step_stuff_spec.concept, wanted_concept=self.output.concept):msg = (- f"PipeSequence concept mismatch: the output concept '{last_step_output_concept.concept_string}' "+ f"PipeSequence concept mismatch: the output concept '{last_step_stuff_spec.concept.concept_string}' "f"of the last step '{last_step_pipe_code}' of sequence pipe '{self.code}' "- f"is not compatible with the output concept '{self.output.concept_string}' of the sequence."+ f"is not compatible with the output concept '{self.output.concept.concept_string}' of the sequence.")raise PipeValidationError(message=msg,error_type=PipeValidationErrorType.INADEQUATE_OUTPUT_CONCEPT,domain=self.domain,pipe_code=self.code,- provided_concept_code=last_step_output_concept.concept_string,- required_concept_codes=[self.output.concept_string],+ provided_concept_code=last_step_stuff_spec.concept.concept_string,+ required_concept_codes=[self.output.concept.concept_string],+ )++ # Check multiplicity match+ if self.output.multiplicity != last_step_stuff_spec.multiplicity:+ msg = (+ f"PipeSequence output multiplicity mismatch: the sequence '{self.code}' declares "+ f"output multiplicity={self.output.multiplicity}, but the last step '{last_step_pipe_code}' "+ f"has output multiplicity={last_step_stuff_spec.multiplicity}. They must be the same."+ )+ raise PipeValidationError(+ message=msg,+ error_type=PipeValidationErrorType.INADEQUATE_OUTPUT_MULTIPLICITY,+ domain=self.domain,+ pipe_code=self.code,+ provided_concept_code=last_step_stuff_spec.concept.concept_string,+ required_concept_codes=[self.output.concept.concept_string],)@override- def needed_inputs(self, visited_pipes: set[str] | None = None) -> InputRequirements:+ def needed_inputs(self, visited_pipes: set[str] | None = None) -> InputStuffSpecs:if visited_pipes is None:visited_pipes = set()# If we've already visited this pipe, stop recursionif self.code in visited_pipes:- return InputRequirementsFactory.make_empty()+ return InputStuffSpecsFactory.make_empty()# Add this pipe to visited set for recursive callsvisited_pipes_with_current = visited_pipes | {self.code}- needed_inputs = InputRequirementsFactory.make_empty()+ needed_inputs = InputStuffSpecsFactory.make_empty()generated_outputs: set[str] = set()for sequential_sub_pipe in self.sequential_sub_pipes:@@ -99,27 +119,27 @@ class PipeSequence(PipeController):if sequential_sub_pipe.batch_params:if sequential_sub_pipe.batch_params.input_list_stuff_name not in generated_outputs:try:- requirement = sub_pipe_needed_inputs.get_required_input_requirement(+ stuff_spec = sub_pipe_needed_inputs.get_required_stuff_spec(variable_name=sequential_sub_pipe.batch_params.input_item_stuff_name)- except PipeInputNotFoundError as exc:+ except InputStuffSpecNotFoundError as exc:msg = (f"Batch input item named '{sequential_sub_pipe.batch_params.input_item_stuff_name}' is not "f"in this PipeSequence '{self.code}' input requirements: {sub_pipe_needed_inputs}")raise PipeSequenceValueError(msg) from exc- needed_inputs.add_requirement(+ needed_inputs.add_stuff_spec(variable_name=sequential_sub_pipe.batch_params.input_list_stuff_name,- concept=requirement.concept,+ concept=stuff_spec.concept,multiplicity=True,)- for input_name, requirement in sub_pipe_needed_inputs.items:+ for input_name, stuff_spec in sub_pipe_needed_inputs.items:if input_name != sequential_sub_pipe.batch_params.input_item_stuff_name and input_name not in generated_outputs:- needed_inputs.add_requirement(input_name, requirement.concept, requirement.multiplicity)+ needed_inputs.add_stuff_spec(input_name, stuff_spec.concept, stuff_spec.multiplicity)else:- for input_name, requirement in sub_pipe_needed_inputs.items:+ for input_name, stuff_spec in sub_pipe_needed_inputs.items:if input_name not in generated_outputs:- needed_inputs.add_requirement(input_name, requirement.concept, requirement.multiplicity)+ needed_inputs.add_stuff_spec(input_name, stuff_spec.concept, stuff_spec.multiplicity)# Add this step's output to generated outputsif sequential_sub_pipe.output_name:@@ -173,17 +193,18 @@ class PipeSequence(PipeController):) -> PipeOutput:if not pipe_run_params.run_mode.is_dry:msg = f"PipeSequence._dry_run_controller_pipe() called with run_mode = {pipe_run_params.run_mode} in pipe {self.code}"- raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode)+ raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode, pipe_code=self.code)# Verify the output of this pipe is matching the output of the last step.- concept_of_last_step = get_required_pipe(pipe_code=self.sequential_sub_pipes[-1].pipe_code).output++ concept_of_last_step = get_required_pipe(pipe_code=self.sequential_sub_pipes[-1].pipe_code).output.concept# if self.output.concept_string != concept_string_of_last_step:- if not get_concept_library().is_compatible(tested_concept=concept_of_last_step, wanted_concept=self.output):+ if not get_concept_library().is_compatible(tested_concept=concept_of_last_step, wanted_concept=self.output.concept):msg = f"""PipeSequence concept mismatch:the output concept '{concept_of_last_step.concept_string}' of the last step '{self.sequential_sub_pipes[-1].pipe_code}'-of sequence pipe '{self.code}' is not compatible with the output concept '{self.output.concept_string}' of the sequence.+of sequence pipe '{self.code}' is not compatible with the output concept '{self.output.concept.concept_string}' of the sequence."""raise PipeControllerOutputConceptMismatchError(- message=msg, tested_concept=concept_of_last_step.concept_string, wanted_concept=self.output.concept_string+ message=msg, tested_concept=concept_of_last_step.concept_string, wanted_concept=self.output.concept.concept_string)return await self._run_controller_pipe(job_metadata=job_metadata,diff --git a/pipelex/pipe_controllers/sequence/pipe_sequence_factory.py b/pipelex/pipe_controllers/sequence/pipe_sequence_factory.pyindex 499a71512..d9f2f1c76 100644--- a/pipelex/pipe_controllers/sequence/pipe_sequence_factory.py+++ b/pipelex/pipe_controllers/sequence/pipe_sequence_factory.py@@ -2,9 +2,9 @@ from typing import TYPE_CHECKING, Anyfrom typing_extensions import override-from pipelex.core.concepts.concept import Concept-from pipelex.core.pipes.inputs.input_requirements import InputRequirements+from pipelex.core.pipes.inputs.input_stuff_specs import InputStuffSpecsfrom pipelex.core.pipes.pipe_factory import PipeFactoryProtocol+from pipelex.core.pipes.stuff_spec.stuff_spec import StuffSpecfrom pipelex.pipe_controllers.sequence.pipe_sequence import PipeSequencefrom pipelex.pipe_controllers.sequence.pipe_sequence_blueprint import PipeSequenceBlueprintfrom pipelex.pipe_controllers.sub_pipe_factory import SubPipeFactory@@ -23,8 +23,8 @@ class PipeSequenceFactory(PipeFactoryProtocol[PipeSequenceBlueprint, PipeSequencpipe_code: str,domain_code: str,description: str | None,- inputs: InputRequirements,- output: Concept,+ inputs: InputStuffSpecs,+ output: StuffSpec,blueprint: PipeSequenceBlueprint,) -> PipeSequence:sequential_sub_pipes: list[SubPipe] = []diff --git a/pipelex/pipe_controllers/sub_pipe.py b/pipelex/pipe_controllers/sub_pipe.pyindex 9a738b3bf..2f769bf16 100644--- a/pipelex/pipe_controllers/sub_pipe.py+++ b/pipelex/pipe_controllers/sub_pipe.py@@ -3,7 +3,7 @@ from pydantic import BaseModelfrom pipelex import logfrom pipelex.core.memory.exceptions import WorkingMemoryStuffNotFoundErrorfrom pipelex.core.memory.working_memory import WorkingMemory-from pipelex.core.pipes.inputs.exceptions import PipeInputError, PipeInputNotFoundError+from pipelex.core.pipes.inputs.exceptions import InputStuffSpecNotFoundError, PipeRunInputsErrorfrom pipelex.core.pipes.pipe_factory import PipeFactoryfrom pipelex.core.pipes.pipe_output import PipeOutputfrom pipelex.core.pipes.variable_multiplicity import VariableMultiplicity@@ -45,28 +45,38 @@ class SubPipe(BaseModel):f"Input list stuff named '{batch_params.input_list_stuff_name}' required by sub_pipe '{self.pipe_code}' "f"of pipe '{calling_pipe_code}' not found in working memory: {exc}")- raise PipeInputError(- message=msg, pipe_code=self.pipe_code, variable_name=batch_params.input_list_stuff_name, concept_code=None+ raise PipeRunInputsError(+ message=msg,+ run_mode=sub_pipe_run_params.run_mode,+ pipe_code=self.pipe_code,+ missing_inputs={},+ variable_name=batch_params.input_list_stuff_name,+ concept_code=None,) from exctry:- item_stuff_requirement = sub_pipe.inputs.get_required_input_requirement(variable_name=batch_params.input_item_stuff_name)- except PipeInputNotFoundError as exc:+ item_stuff_spec = sub_pipe.inputs.get_required_stuff_spec(variable_name=batch_params.input_item_stuff_name)+ except InputStuffSpecNotFoundError as exc:msg = (f"Batch input item named '{batch_params.input_item_stuff_name}' from '{calling_pipe_code}' is not "- f"in SubPipe '{self.pipe_code}' input requirements: {sub_pipe.inputs}"+ f"in SubPipe '{self.pipe_code}' input stuff specs: {sub_pipe.inputs}")- raise PipeInputError(- message=msg, pipe_code=self.pipe_code, variable_name=batch_params.input_item_stuff_name, concept_code=None+ raise PipeRunInputsError(+ message=msg,+ run_mode=sub_pipe_run_params.run_mode,+ pipe_code=self.pipe_code,+ missing_inputs={},+ variable_name=batch_params.input_item_stuff_name,+ concept_code=None,) from excpipe_batch_blueprint = PipeBatchBlueprint(description=f"Batch processing for {self.pipe_code}",branch_pipe_code=self.pipe_code,- output=sub_pipe.output.code,+ output=sub_pipe.output.concept.code,input_list_name=batch_params.input_list_stuff_name,input_item_name=batch_params.input_item_stuff_name,inputs={- batch_params.input_list_stuff_name: item_stuff_requirement.concept.concept_string,+ batch_params.input_list_stuff_name: item_stuff_spec.concept.concept_string,},)@@ -101,7 +111,14 @@ class SubPipe(BaseModel):sub_pipe_path_str = ".".join(sub_pipe_path)error_details = f"SubPipe '{sub_pipe_path_str}', required_variables: {required_variables}, missing: '{exc.variable_name}'"msg = f"Some required stuff(s) not found: {error_details}"- raise PipeInputError(message=msg, pipe_code=self.pipe_code, variable_name=exc.variable_name, concept_code=None) from exc+ raise PipeRunInputsError(+ message=msg,+ run_mode=sub_pipe_run_params.run_mode,+ pipe_code=self.pipe_code,+ missing_inputs={},+ variable_name=exc.variable_name,+ concept_code=None,+ ) from exclog.verbose(required_stuffs, title=f"Required stuffs for {self.pipe_code}")pipe_output = await sub_pipe.run_pipe(job_metadata=job_metadata,diff --git a/pipelex/pipe_operators/compose/pipe_compose.py b/pipelex/pipe_operators/compose/pipe_compose.pyindex e5c4c9c30..12ad7a099 100644--- a/pipelex/pipe_operators/compose/pipe_compose.py+++ b/pipelex/pipe_operators/compose/pipe_compose.py@@ -9,13 +9,11 @@ from pipelex.cogt.content_generation.content_generator_protocol import ContentGefrom pipelex.cogt.templating.template_category import TemplateCategoryfrom pipelex.cogt.templating.templating_style import TemplatingStylefrom pipelex.config import get_config-from pipelex.core.concepts.concept import Concept-from pipelex.core.concepts.concept_factory import ConceptFactoryfrom pipelex.core.concepts.native.concept_native import NativeConceptCodefrom pipelex.core.memory.working_memory import WorkingMemoryfrom pipelex.core.pipes.exceptions import PipeValidationError, PipeValidationErrorType-from pipelex.core.pipes.inputs.input_requirements import InputRequirements-from pipelex.core.pipes.inputs.input_requirements_factory import InputRequirementsFactory+from pipelex.core.pipes.inputs.input_stuff_specs import InputStuffSpecs+from pipelex.core.pipes.inputs.input_stuff_specs_factory import InputStuffSpecsFactoryfrom pipelex.core.pipes.pipe_output import PipeOutputfrom pipelex.core.stuffs.stuff_content import StuffContentfrom pipelex.core.stuffs.stuff_factory import StuffFactory@@ -37,11 +35,6 @@ class PipeComposeOutput(PipeOutput):class PipeCompose(PipeOperator[PipeComposeOutput]):type: Literal["PipeCompose"] = "PipeCompose"model_config = ConfigDict(extra="forbid", strict=False)-- output: Concept = ConceptFactory.make_native_concept(- native_concept_code=NativeConceptCode.TEXT,- )-template: strtemplating_style: TemplatingStyle | None = Nonecategory: TemplateCategory = TemplateCategory.BASIC@@ -69,10 +62,10 @@ class PipeCompose(PipeOperator[PipeComposeOutput]):@override# TODO: this needs testing!!!- def needed_inputs(self, visited_pipes: set[str] | None = None) -> InputRequirements:- needed_inputs = InputRequirementsFactory.make_empty()- for input_name, requirement in self.inputs.root.items():- needed_inputs.add_requirement(variable_name=input_name, concept=requirement.concept, multiplicity=requirement.multiplicity)+ def needed_inputs(self, visited_pipes: set[str] | None = None) -> InputStuffSpecs:+ needed_inputs = InputStuffSpecsFactory.make_empty()+ for input_name, stuff_spec in self.inputs.root.items():+ needed_inputs.add_stuff_spec(variable_name=input_name, concept=stuff_spec.concept, multiplicity=stuff_spec.multiplicity)return needed_inputs@override@@ -90,13 +83,13 @@ class PipeCompose(PipeOperator[PipeComposeOutput]):@overridedef validate_output_with_library(self):if not get_concept_library().is_compatible(- tested_concept=self.output,+ tested_concept=self.output.concept,wanted_concept=get_native_concept(native_concept=NativeConceptCode.TEXT),strict=True,):msg = (f"The output of a PipeCompose must be strictly compatible with the Text concept. "- f"In the pipe '{self.code}' the output is '{self.output.concept_string}'. "+ f"In the pipe '{self.code}' the output is '{self.output.concept.concept_string}'. ""Make sure this concept refines the native Text concept.")raise PipeValidationError(@@ -104,7 +97,7 @@ class PipeCompose(PipeOperator[PipeComposeOutput]):error_type=PipeValidationErrorType.INADEQUATE_OUTPUT_CONCEPT,domain=self.domain,pipe_code=self.code,- provided_concept_code=self.output.concept_string,+ provided_concept_code=self.output.concept.concept_string,required_concept_codes=[NativeConceptCode.TEXT.concept_string],)@@ -139,12 +132,12 @@ class PipeCompose(PipeOperator[PipeComposeOutput]):# Get the structure class from the registry (might be a subclass of TextContent)structure_class = get_class_registry().get_required_subclass(- name=self.output.structure_class_name,+ name=self.output.concept.structure_class_name,base_class=StuffContent,)the_content = structure_class(text=jinja2_text)- output_stuff = StuffFactory.make_stuff(concept=self.output, content=the_content, name=output_name)+ output_stuff = StuffFactory.make_stuff(concept=self.output.concept, content=the_content, name=output_name)working_memory.set_new_main_stuff(stuff=output_stuff,diff --git a/pipelex/pipe_operators/compose/pipe_compose_factory.py b/pipelex/pipe_operators/compose/pipe_compose_factory.pyindex caf671d12..caeb51558 100644--- a/pipelex/pipe_operators/compose/pipe_compose_factory.py+++ b/pipelex/pipe_operators/compose/pipe_compose_factory.py@@ -3,9 +3,9 @@ from typing import Anyfrom typing_extensions import overridefrom pipelex.cogt.templating.template_preprocessor import preprocess_template-from pipelex.core.concepts.concept import Concept-from pipelex.core.pipes.inputs.input_requirements import InputRequirements+from pipelex.core.pipes.inputs.input_stuff_specs import InputStuffSpecsfrom pipelex.core.pipes.pipe_factory import PipeFactoryProtocol+from pipelex.core.pipes.stuff_spec.stuff_spec import StuffSpecfrom pipelex.pipe_operators.compose.exceptions import PipeComposeFactoryErrorfrom pipelex.pipe_operators.compose.pipe_compose import PipeComposefrom pipelex.pipe_operators.compose.pipe_compose_blueprint import PipeComposeBlueprint@@ -23,8 +23,8 @@ class PipeComposeFactory(PipeFactoryProtocol[PipeComposeBlueprint, PipeCompose])pipe_code: str,domain_code: str,description: str | None,- inputs: InputRequirements,- output: Concept,+ inputs: InputStuffSpecs,+ output: StuffSpec,blueprint: PipeComposeBlueprint,) -> PipeCompose:preprocessed_template = preprocess_template(blueprint.template_source)diff --git a/pipelex/pipe_operators/extract/pipe_extract.py b/pipelex/pipe_operators/extract/pipe_extract.pyindex db570dc35..9b7d60fb4 100644--- a/pipelex/pipe_operators/extract/pipe_extract.py+++ b/pipelex/pipe_operators/extract/pipe_extract.py@@ -14,7 +14,7 @@ from pipelex.cogt.models.model_deck_check import check_extract_choice_with_deckfrom pipelex.core.concepts.native.concept_native import NativeConceptCodefrom pipelex.core.memory.working_memory import WorkingMemoryfrom pipelex.core.pipes.exceptions import PipeValidationError, PipeValidationErrorType-from pipelex.core.pipes.inputs.input_requirements import InputRequirements+from pipelex.core.pipes.inputs.input_stuff_specs import InputStuffSpecsfrom pipelex.core.pipes.pipe_output import PipeOutputfrom pipelex.core.stuffs.image_content import ImageContentfrom pipelex.core.stuffs.list_content import ListContent@@ -51,7 +51,7 @@ class PipeExtract(PipeOperator[PipeExtractOutput]):pdf_stuff_name: str | None = None@override- def needed_inputs(self, visited_pipes: set[str] | None = None) -> InputRequirements:+ def needed_inputs(self, visited_pipes: set[str] | None = None) -> InputStuffSpecs:return self.inputs@override@@ -84,14 +84,14 @@ class PipeExtract(PipeOperator[PipeExtractOutput]):@overridedef validate_output_with_library(self):- if self.output != get_native_concept(native_concept=NativeConceptCode.PAGE):- msg = f"PipeExtract output should be a Page concept, but is {self.output.concept_string}"+ if self.output.concept != get_native_concept(native_concept=NativeConceptCode.PAGE):+ msg = f"PipeExtract output should be a Page concept, but is {self.output.concept.concept_string}"raise PipeValidationError(message=msg,error_type=PipeValidationErrorType.INADEQUATE_OUTPUT_CONCEPT,domain=self.domain,pipe_code=self.code,- provided_concept_code=self.output.concept_string,+ provided_concept_code=self.output.concept.concept_string,required_concept_codes=[NativeConceptCode.PAGE.concept_string],)@@ -183,7 +183,7 @@ class PipeExtract(PipeOperator[PipeExtractOutput]):output_stuff = StuffFactory.make_stuff(name=output_name,- concept=self.output,+ concept=self.output.concept,content=content,)@@ -208,7 +208,7 @@ class PipeExtract(PipeOperator[PipeExtractOutput]):log.verbose(f"PipeExtract: dry run operator pipe: {self.code}")if pipe_run_params.run_mode != PipeRunMode.DRY:msg = f"Running pipe '{self.code}' (PipeExtract) _dry_run_operator_pipe() in non-dry mode is not allowed."- raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode)+ raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode, pipe_code=self.code)content_generator_dry = ContentGeneratorDry()return await self._run_operator_pipe(diff --git a/pipelex/pipe_operators/extract/pipe_extract_factory.py b/pipelex/pipe_operators/extract/pipe_extract_factory.pyindex 0840abc17..72b76b421 100644--- a/pipelex/pipe_operators/extract/pipe_extract_factory.py+++ b/pipelex/pipe_operators/extract/pipe_extract_factory.py@@ -3,10 +3,10 @@ from typing import Anyfrom typing_extensions import overridefrom pipelex.config import get_config-from pipelex.core.concepts.concept import Conceptfrom pipelex.core.concepts.native.concept_native import NativeConceptCode-from pipelex.core.pipes.inputs.input_requirements import InputRequirements+from pipelex.core.pipes.inputs.input_stuff_specs import InputStuffSpecsfrom pipelex.core.pipes.pipe_factory import PipeFactoryProtocol+from pipelex.core.pipes.stuff_spec.stuff_spec import StuffSpecfrom pipelex.hub import get_concept_library, get_native_conceptfrom pipelex.pipe_operators.extract.exceptions import PipeExtractFactoryErrorfrom pipelex.pipe_operators.extract.pipe_extract import PipeExtract@@ -23,8 +23,8 @@ class PipeExtractFactory(PipeFactoryProtocol[PipeExtractBlueprint, PipeExtract])pipe_code: str,domain_code: str,description: str | None,- inputs: InputRequirements,- output: Concept,+ inputs: InputStuffSpecs,+ output: StuffSpec,blueprint: PipeExtractBlueprint,) -> PipeExtract:concept_library = get_concept_library()@@ -33,7 +33,7 @@ class PipeExtractFactory(PipeFactoryProtocol[PipeExtractBlueprint, PipeExtract])# Already validated above that we have exactly one inputinput_name = blueprint.input_names[0]- input_requirement = inputs.get_required_input_requirement(input_name)+ input_requirement = inputs.get_required_stuff_spec(input_name)if concept_library.is_compatible(tested_concept=input_requirement.concept,diff --git a/pipelex/pipe_operators/func/pipe_func.py b/pipelex/pipe_operators/func/pipe_func.pyindex 8446b7501..c6fc7abca 100644--- a/pipelex/pipe_operators/func/pipe_func.py+++ b/pipelex/pipe_operators/func/pipe_func.py@@ -8,7 +8,7 @@ from pipelex import logfrom pipelex.core.concepts.concept_factory import ConceptFactoryfrom pipelex.core.memory.working_memory import WorkingMemoryfrom pipelex.core.memory.working_memory_factory import WorkingMemoryFactory-from pipelex.core.pipes.inputs.input_requirements import InputRequirements, TypedNamedInputRequirement+from pipelex.core.pipes.inputs.input_stuff_specs import InputStuffSpecs, TypedNamedStuffSpecfrom pipelex.core.pipes.pipe_output import PipeOutputfrom pipelex.core.stuffs.list_content import ListContentfrom pipelex.core.stuffs.stuff_content import StuffContent@@ -34,7 +34,7 @@ class PipeFunc(PipeOperator[PipeFuncOutput]):return set()@override- def needed_inputs(self, visited_pipes: set[str] | None = None) -> InputRequirements:+ def needed_inputs(self, visited_pipes: set[str] | None = None) -> InputStuffSpecs:return self.inputs@field_validator("function_name", mode="before")@@ -102,7 +102,7 @@ class PipeFunc(PipeOperator[PipeFuncOutput]):output_stuff = StuffFactory.make_stuff(name=output_name,- concept=self.output,+ concept=self.output.concept,content=the_content,)@@ -132,42 +132,42 @@ class PipeFunc(PipeOperator[PipeFuncOutput]):needed_inputs = self.needed_inputs()missing_input_names: list[str] = []- for named_input_requirement in needed_inputs.named_input_requirements:- if not working_memory.get_optional_stuff(named_input_requirement.variable_name):- missing_input_names.append(named_input_requirement.variable_name)+ for named_stuff_spec in needed_inputs.named_stuff_specs:+ if not working_memory.get_optional_stuff(named_stuff_spec.variable_name):+ missing_input_names.append(named_stuff_spec.variable_name)if missing_input_names:msg = f"Dry run failed for pipe '{self.code}' (PipeFunc): missing required inputs: {missing_input_names}"- raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode)+ raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode, pipe_code=self.code)return_type = get_type_hints(function).get("return")if return_type is None:msg = f"Dry run failed for pipe '{self.code}' (PipeFunc): function '{self.function_name}' has no return type annotation"- raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode)+ raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode, pipe_code=self.code)if not issubclass(return_type, StuffContent):msg = (f"Dry run failed for pipe '{self.code}' (PipeFunc): "f"function '{self.function_name}' return type {return_type} is not a subclass of StuffContent")- raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode)+ raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode, pipe_code=self.code)# TODO: Support PipeFunc returning with multiplicity. Create an equivalent of TypedNamedInputRequirement for outputs.- requirement = TypedNamedInputRequirement(+ stuff_spec = TypedNamedStuffSpec(variable_name="mock_output",concept=ConceptFactory.make(- concept_code=self.output.code,+ concept_code=self.output.concept.code,domain="generic",description="Lorem Ipsum",- structure_class_name=self.output.structure_class_name,+ structure_class_name=self.output.concept.structure_class_name,),structure_class=return_type,multiplicity=False,)- mock_content = WorkingMemoryFactory.create_mock_content(requirement)+ mock_content = WorkingMemoryFactory.create_mock_content(stuff_spec)output_stuff = StuffFactory.make_stuff(name=output_name,- concept=self.output,+ concept=self.output.concept,content=mock_content,)diff --git a/pipelex/pipe_operators/func/pipe_func_factory.py b/pipelex/pipe_operators/func/pipe_func_factory.pyindex f4a4e79d5..00c50d178 100644--- a/pipelex/pipe_operators/func/pipe_func_factory.py+++ b/pipelex/pipe_operators/func/pipe_func_factory.py@@ -2,9 +2,9 @@ from typing import Anyfrom typing_extensions import override-from pipelex.core.concepts.concept import Concept-from pipelex.core.pipes.inputs.input_requirements import InputRequirements+from pipelex.core.pipes.inputs.input_stuff_specs import InputStuffSpecsfrom pipelex.core.pipes.pipe_factory import PipeFactoryProtocol+from pipelex.core.pipes.stuff_spec.stuff_spec import StuffSpecfrom pipelex.pipe_operators.func.pipe_func import PipeFuncfrom pipelex.pipe_operators.func.pipe_func_blueprint import PipeFuncBlueprint@@ -19,8 +19,8 @@ class PipeFuncFactory(PipeFactoryProtocol[PipeFuncBlueprint, PipeFunc]):pipe_code: str,domain_code: str,description: str | None,- inputs: InputRequirements,- output: Concept,+ inputs: InputStuffSpecs,+ output: StuffSpec,blueprint: PipeFuncBlueprint,) -> PipeFunc:# TODO: make function_name into a callable in PipeFuncdiff --git a/pipelex/pipe_operators/img_gen/pipe_img_gen.py b/pipelex/pipe_operators/img_gen/pipe_img_gen.pyindex 2e8a454bf..43339bd48 100644--- a/pipelex/pipe_operators/img_gen/pipe_img_gen.py+++ b/pipelex/pipe_operators/img_gen/pipe_img_gen.py@@ -16,7 +16,7 @@ from pipelex.core.concepts.native.concept_native import NativeConceptCodefrom pipelex.core.memory.exceptions import WorkingMemoryStuffNotFoundErrorfrom pipelex.core.memory.working_memory import WorkingMemoryfrom pipelex.core.pipes.exceptions import PipeValidationError, PipeValidationErrorType-from pipelex.core.pipes.inputs.input_requirements import InputRequirements+from pipelex.core.pipes.inputs.input_stuff_specs import InputStuffSpecsfrom pipelex.core.pipes.pipe_output import PipeOutputfrom pipelex.core.pipes.variable_multiplicity import VariableMultiplicityfrom pipelex.core.stuffs.exceptions import StuffContentTypeError@@ -56,7 +56,7 @@ class PipeImgGen(PipeOperator[PipeImgGenOutput]):output_multiplicity: VariableMultiplicity@override- def needed_inputs(self, visited_pipes: set[str] | None = None) -> InputRequirements:+ def needed_inputs(self, visited_pipes: set[str] | None = None) -> InputStuffSpecs:"""Needed inputs are the inputs needed to run the pipe, specified in the inputs attribute of the pipe"""return self.inputs@@ -81,20 +81,20 @@ class PipeImgGen(PipeOperator[PipeImgGenOutput]):@overridedef validate_output_with_library(self):if not get_concept_library().is_compatible(- tested_concept=self.output,+ tested_concept=self.output.concept,wanted_concept=get_native_concept(native_concept=NativeConceptCode.IMAGE),strict=True,):msg = (f"The output of a PipeImgGen must be compatible with the Image concept. "- f"In the pipe '{self.code}' the output is '{self.output.concept_string}'"+ f"In the pipe '{self.code}' the output is '{self.output.concept.concept_string}'")raise PipeValidationError(message=msg,error_type=PipeValidationErrorType.INADEQUATE_OUTPUT_CONCEPT,domain=self.domain,pipe_code=self.code,- provided_concept_code=self.output.concept_string,+ provided_concept_code=self.output.concept.concept_string,required_concept_codes=[NativeConceptCode.IMAGE.concept_string],)@@ -189,7 +189,7 @@ class PipeImgGen(PipeOperator[PipeImgGenOutput]):# Get the structure class from the registry (might be a subclass of ImageContent)structure_class = get_class_registry().get_required_subclass(- name=self.output.structure_class_name,+ name=self.output.concept.structure_class_name,base_class=ImageContent,)base_64_str: str | None@@ -242,7 +242,7 @@ class PipeImgGen(PipeOperator[PipeImgGenOutput]):output_stuff = StuffFactory.make_stuff(name=output_name,- concept=self.output,+ concept=self.output.concept,content=the_content,)diff --git a/pipelex/pipe_operators/img_gen/pipe_img_gen_factory.py b/pipelex/pipe_operators/img_gen/pipe_img_gen_factory.pyindex ca856fe02..b0ff4b5e7 100644--- a/pipelex/pipe_operators/img_gen/pipe_img_gen_factory.py+++ b/pipelex/pipe_operators/img_gen/pipe_img_gen_factory.py@@ -4,9 +4,9 @@ from typing_extensions import overridefrom pipelex.cogt.templating.template_blueprint import TemplateBlueprintfrom pipelex.cogt.templating.template_category import TemplateCategory-from pipelex.core.concepts.concept import Concept-from pipelex.core.pipes.inputs.input_requirements import InputRequirements+from pipelex.core.pipes.inputs.input_stuff_specs import InputStuffSpecsfrom pipelex.core.pipes.pipe_factory import PipeFactoryProtocol+from pipelex.core.pipes.stuff_spec.stuff_spec import StuffSpecfrom pipelex.core.pipes.variable_multiplicity import parse_concept_with_multiplicityfrom pipelex.pipe_operators.img_gen.pipe_img_gen import PipeImgGenfrom pipelex.pipe_operators.img_gen.pipe_img_gen_blueprint import PipeImgGenBlueprint@@ -22,8 +22,8 @@ class PipeImgGenFactory(PipeFactoryProtocol[PipeImgGenBlueprint, PipeImgGen]):pipe_code: str,domain_code: str,description: str | None,- inputs: InputRequirements,- output: Concept,+ inputs: InputStuffSpecs,+ output: StuffSpec,blueprint: PipeImgGenBlueprint,) -> PipeImgGen:# Parse output for multiplicity (may have brackets like "Image[]" or "Image[3]")diff --git a/pipelex/pipe_operators/llm/pipe_llm.py b/pipelex/pipe_operators/llm/pipe_llm.pyindex 5c9ae5f54..6741eb036 100644--- a/pipelex/pipe_operators/llm/pipe_llm.py+++ b/pipelex/pipe_operators/llm/pipe_llm.py@@ -20,8 +20,8 @@ from pipelex.core.concepts.native.concept_native import NativeConceptCodefrom pipelex.core.domains.domain import SpecialDomainfrom pipelex.core.memory.working_memory import WorkingMemoryfrom pipelex.core.pipes.exceptions import PipeValidationError, PipeValidationErrorType-from pipelex.core.pipes.inputs.input_requirements import InputRequirements-from pipelex.core.pipes.inputs.input_requirements_factory import InputRequirementsFactory+from pipelex.core.pipes.inputs.input_stuff_specs import InputStuffSpecs+from pipelex.core.pipes.inputs.input_stuff_specs_factory import InputStuffSpecsFactoryfrom pipelex.core.pipes.pipe_output import PipeOutputfrom pipelex.core.pipes.variable_multiplicity import VariableMultiplicityfrom pipelex.core.stuffs.list_content import ListContent@@ -63,9 +63,9 @@ class PipeLLM(PipeOperator[PipeLLMOutput]):@model_validator(mode="after")def validate_output_concept_consistency(self) -> Self:- if self.structuring_method is not None and self.output.structure_class_name == NativeConceptCode.TEXT:+ if self.structuring_method is not None and self.output.concept.structure_class_name == NativeConceptCode.TEXT:msg = (- f"Output concept '{self.output.code}' is considered a Text concept, "+ f"Output concept '{self.output.concept.code}' is considered a Text concept, "f"so it cannot be structured. Maybe you forgot to add '{NativeConceptCode.TEXT}' to the class registry?")raise ValueError(msg)@@ -91,32 +91,32 @@ class PipeLLM(PipeOperator[PipeLLMOutput]):# and PipeLLM is not the only one with this kind of constraints# Allow Dynamic output concept as it's flexible and can represent anything- if NativeConceptCode.is_dynamic_concept(concept_code=self.output.code):+ if NativeConceptCode.is_dynamic_concept(concept_code=self.output.concept.code):returnif get_concept_library().is_compatible(- tested_concept=self.output,+ tested_concept=self.output.concept,wanted_concept=get_native_concept(native_concept=NativeConceptCode.IMAGE),):msg = (f"The output of the PipeLLM '{self.code}' cannot be compatible with the Image concept. "- f"The output concept is '{self.output.concept_string}'. "+ f"The output concept is '{self.output.concept.concept_string}'. ""Use a PipeImgGen if you want to generate images. You can use a PipeLLM to generate the prompt for a PipeImgGen.")raise PipeValidationError(message=msg,error_type=PipeValidationErrorType.LLM_OUTPUT_CANNOT_BE_IMAGE,pipe_code=self.code,- provided_concept_code=self.output.concept_string,+ provided_concept_code=self.output.concept.concept_string,)@override- def needed_inputs(self, visited_pipes: set[str] | None = None) -> InputRequirements:+ def needed_inputs(self, visited_pipes: set[str] | None = None) -> InputStuffSpecs:"""Needed inputs are the inputs needed to run the pipe, specified in the inputs attribute of the pipe"""- needed_inputs = InputRequirementsFactory.make_empty()+ needed_inputs = InputStuffSpecsFactory.make_empty()- for input_name, requirement in self.inputs.items:- needed_inputs.add_requirement(variable_name=input_name, concept=requirement.concept, multiplicity=requirement.multiplicity)+ for input_name, stuff_spec in self.inputs.items:+ needed_inputs.add_stuff_spec(variable_name=input_name, concept=stuff_spec.concept, multiplicity=stuff_spec.multiplicity)return needed_inputs@override@@ -136,8 +136,8 @@ class PipeLLM(PipeOperator[PipeLLMOutput]):llm_config = get_config().cogt.llm_configcontent_generator = content_generator or get_content_generator()# interpret / unwrap the arguments- output_concept = self.output- if self.output.code == SpecialDomain.NATIVE + "." + NativeConceptCode.DYNAMIC:+ output_stuff_spec = self.output+ if self.output.concept.code == SpecialDomain.NATIVE + "." + NativeConceptCode.DYNAMIC:# TODO: This DYNAMIC_OUTPUT_CONCEPT should not be a field in the params attribute of PipeRunParams.# It should be an attribute of PipeRunParams.output_concept_code = pipe_run_params.dynamic_output_concept_code or pipe_run_params.params.get(PipeRunParamKey.DYNAMIC_OUTPUT_CONCEPT)@@ -145,7 +145,7 @@ class PipeLLM(PipeOperator[PipeLLMOutput]):if not output_concept_code:output_concept_code = SpecialDomain.NATIVE + "." + NativeConceptCode.TEXTelse:- output_concept = get_required_concept(+ output_stuff_spec.concept = get_required_concept(concept_string=ConceptFactory.make_concept_string_with_domain(domain=self.domain, concept_code=output_concept_code),)@@ -210,11 +210,11 @@ class PipeLLM(PipeOperator[PipeLLMOutput]):the_content: StuffContentif (- Concept.are_concept_compatible(concept_1=output_concept, concept_2=get_native_concept(NativeConceptCode.TEXT), strict=True)+ Concept.are_concept_compatible(concept_1=output_stuff_spec.concept, concept_2=get_native_concept(NativeConceptCode.TEXT), strict=True)and not is_multiple_output):llm_prompt_1_for_text = await self.llm_prompt_spec.make_llm_prompt(- output_concept_string=output_concept.concept_string,+ output_concept_string=output_stuff_spec.concept.concept_string,context_provider=working_memory,output_structure_prompt=None,extra_params=llm_prompt_run_params.params,@@ -229,10 +229,10 @@ class PipeLLM(PipeOperator[PipeLLMOutput]):location = self._format_error_location(pipe_run_params=pipe_run_params)error_details = self._format_llm_error(exc=exc, settings=[llm_setting_main])msg = f"Error generating text with LLM {location}: {error_details}"- raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode) from exc+ raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode, pipe_code=self.code) from excstructure_class = get_class_registry().get_required_subclass(- name=output_concept.structure_class_name,+ name=output_stuff_spec.concept.structure_class_name,base_class=StuffContent,)@@ -244,12 +244,12 @@ class PipeLLM(PipeOperator[PipeLLMOutput]):location = self._format_error_location(pipe_run_params=pipe_run_params)error_details = format_pydantic_validation_error(exc)msg = f"Error generating text content with in PipeLLM {location}: {error_details}"- raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode) from exc+ raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode, pipe_code=self.code) from excelse:if is_multiple_output:log.verbose(f"PipeLLM generating {fixed_nb_output} output(s)" if fixed_nb_output else "PipeLLM generating a list of output(s)")else:- log.verbose(f"PipeLLM generating a single object output, class name: '{output_concept.structure_class_name}'")+ log.verbose(f"PipeLLM generating a single object output, class name: '{output_stuff_spec.concept.structure_class_name}'")# TODO: we need a better solution for structuring_method (text then object), meanwhile,# we acknowledge the code here with llm_prompt_1 and llm_prompt_2 is overly complex and should be refactored.@@ -273,11 +273,11 @@ class PipeLLM(PipeOperator[PipeLLMOutput]):output_structure_prompt: str | None = Noneif llm_config.is_structure_prompt_enabled:output_structure_prompt = await PipeLLM.get_output_structure_prompt(- concept_string=pipe_run_params.dynamic_output_concept_code or output_concept.concept_string,+ concept_string=pipe_run_params.dynamic_output_concept_code or output_stuff_spec.concept.concept_string,is_with_preliminary_text=is_with_preliminary_text,)llm_prompt_1_for_object = await self.llm_prompt_spec.make_llm_prompt(- output_concept_string=output_concept.concept_string,+ output_concept_string=output_stuff_spec.concept.concept_string,context_provider=working_memory,output_structure_prompt=output_structure_prompt,extra_params=llm_prompt_run_params.params,@@ -287,7 +287,7 @@ class PipeLLM(PipeOperator[PipeLLMOutput]):pipe_run_params=pipe_run_params,is_multiple_output=is_multiple_output,fixed_nb_output=fixed_nb_output,- output_class_name=output_concept.structure_class_name,+ output_class_name=output_stuff_spec.concept.structure_class_name,llm_setting_main=llm_setting_main,llm_setting_for_object=llm_setting_for_object,llm_prompt_1=llm_prompt_1_for_object,@@ -297,7 +297,7 @@ class PipeLLM(PipeOperator[PipeLLMOutput]):output_stuff = StuffFactory.make_stuff(name=output_name,- concept=output_concept,+ concept=output_stuff_spec.concept,content=the_content,code=pipe_run_params.final_stuff_code,)@@ -355,7 +355,7 @@ class PipeLLM(PipeOperator[PipeLLMOutput]):location = self._format_error_location(pipe_run_params=pipe_run_params)error_details = self._format_llm_error(exc=exc, settings=[llm_setting_main, llm_setting_for_object])msg = f"Error generating list of objects with text then object {location}: {error_details}"- raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode) from exc+ raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode, pipe_code=self.code) from excelse:# We're generating a list of objects directlymethod_desc = "object_direct"@@ -372,7 +372,7 @@ class PipeLLM(PipeOperator[PipeLLMOutput]):location = self._format_error_location(pipe_run_params=pipe_run_params)error_details = self._format_llm_error(exc=exc, settings=[llm_setting_for_object])msg = f"Error generating list of objects with direct method {location}: {error_details}"- raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode) from exc+ raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode, pipe_code=self.code) from excthe_content = ListContent(items=generated_objects)else:@@ -397,7 +397,7 @@ class PipeLLM(PipeOperator[PipeLLMOutput]):location = self._format_error_location(pipe_run_params=pipe_run_params)error_details = self._format_llm_error(exc=exc, settings=[llm_setting_main, llm_setting_for_object])msg = f"Error generating single object with text then object {location}: {error_details}"- raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode) from exc+ raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode, pipe_code=self.code) from excelse:# We're generating a single object directlymethod_desc = "object_direct"@@ -413,7 +413,7 @@ class PipeLLM(PipeOperator[PipeLLMOutput]):location = self._format_error_location(pipe_run_params=pipe_run_params)error_details = self._format_llm_error(exc=exc, settings=[llm_setting_for_object])msg = f"Error generating single object with direct method {location}: {error_details}"- raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode) from exc+ raise PipeRunError(message=msg, run_mode=pipe_run_params.run_mode, pipe_code=self.code) from excthe_content = generated_objectreturn the_contentdiff --git a/pipelex/pipe_operators/llm/pipe_llm_factory.py b/pipelex/pipe_operators/llm/pipe_llm_factory.pyindex fef79dc7a..4323aa88b 100644--- a/pipelex/pipe_operators/llm/pipe_llm_factory.py+++ b/pipelex/pipe_operators/llm/pipe_llm_factory.py@@ -9,8 +9,9 @@ from pipelex.cogt.templating.template_category import TemplateCategoryfrom pipelex.core.concepts.concept import Conceptfrom pipelex.core.concepts.concept_factory import ConceptFactoryfrom pipelex.core.concepts.native.concept_native import NativeConceptCode-from pipelex.core.pipes.inputs.input_requirements import InputRequirements+from pipelex.core.pipes.inputs.input_stuff_specs import InputStuffSpecsfrom pipelex.core.pipes.pipe_factory import PipeFactoryProtocol+from pipelex.core.pipes.stuff_spec.stuff_spec import StuffSpecfrom pipelex.core.pipes.variable_multiplicity import make_variable_multiplicity, parse_concept_with_multiplicityfrom pipelex.hub import get_native_concept, get_optional_domain, get_required_conceptfrom pipelex.pipe_operators.llm.exceptions import PipeLLMFactoryError@@ -30,8 +31,8 @@ class PipeLLMFactory(PipeFactoryProtocol[PipeLLMBlueprint, PipeLLM]):pipe_code: str,domain_code: str,description: str | None,- inputs: InputRequirements,- output: Concept,+ inputs: InputStuffSpecs,+ output: StuffSpec,blueprint: PipeLLMBlueprint,) -> PipeLLM:system_prompt = blueprint.system_promptdiff --git a/pipelex/pipe_operators/pipe_operator.py b/pipelex/pipe_operators/pipe_operator.pyindex 1b9f171b8..8453349f9 100644--- a/pipelex/pipe_operators/pipe_operator.py+++ b/pipelex/pipe_operators/pipe_operator.py@@ -45,7 +45,7 @@ class PipeOperator(PipeAbstract, Generic[PipeOperatorOutputType]):output_name=output_name,)main_stuff = pipe_output.main_stuff- output_concept_code = self.output.code+ output_concept_code = self.output.concept.codeoutput_concept_with_multiplicity = f"[bold green]{output_concept_code}[/bold green]"if main_stuff.is_list:list_content: ListContent[StuffContent] = main_stuff.as_list_content() # pyright: ignore[reportUnknownVariableType, reportUnknownMemberType]diff --git a/pipelex/pipe_run/dry_run.py b/pipelex/pipe_run/dry_run.pyindex 125c9eddd..2b9c9cead 100644--- a/pipelex/pipe_run/dry_run.py+++ b/pipelex/pipe_run/dry_run.py@@ -6,7 +6,7 @@ from pipelex import logfrom pipelex.base_exceptions import PipelexErrorfrom pipelex.config import get_configfrom pipelex.core.memory.working_memory_factory import WorkingMemoryFactory-from pipelex.core.pipes.inputs.input_requirements import InputRequirements, TypedNamedInputRequirement+from pipelex.core.pipes.inputs.input_stuff_specs import InputStuffSpecs, TypedNamedStuffSpecfrom pipelex.core.pipes.pipe_abstract import PipeAbstractfrom pipelex.core.stuffs.stuff_content import StuffContentfrom pipelex.core.stuffs.text_content import TextContent@@ -116,7 +116,7 @@ async def dry_run_pipes(pipes: list[PipeAbstract], raise_on_failure: bool = Truereturn results-def _convert_to_working_memory_format(needed_inputs_spec: InputRequirements) -> list[TypedNamedInputRequirement]:+def _convert_to_working_memory_format(needed_inputs_spec: InputStuffSpecs) -> list[TypedNamedStuffSpec]:"""Convert PipeInput to the format needed by WorkingMemoryFactory.make_for_dry_run.Args:@@ -126,44 +126,44 @@ def _convert_to_working_memory_format(needed_inputs_spec: InputRequirements) ->List of tuples (variable_name, concept_code, structure_class)"""- needed_inputs_for_factory: list[TypedNamedInputRequirement] = []+ needed_inputs_for_factory: list[TypedNamedStuffSpec] = []class_registry = get_class_registry()# TODO: fail and raise properly- for named_input_requirement in needed_inputs_spec.named_input_requirements:+ for named_stuff_spec in needed_inputs_spec.named_stuff_specs:try:# Get the concept and its structure class- concept = named_input_requirement.concept+ concept = named_stuff_spec.conceptstructure_class_name = concept.structure_class_name# Get the actual class from the registrystructure_class = class_registry.get_class(name=structure_class_name)if structure_class and issubclass(structure_class, StuffContent):- typed_named_input_requirement = TypedNamedInputRequirement.make_from_named(- named=named_input_requirement,+ typed_named_stuff_spec = TypedNamedStuffSpec.make_from_named(+ named=named_stuff_spec,structure_class=structure_class,)- needed_inputs_for_factory.append(typed_named_input_requirement)+ needed_inputs_for_factory.append(typed_named_stuff_spec)else:# Fallback to TextContent if we can't get the proper classlog.verbose(f"Could not get structure class '{structure_class_name}' for "- f"concept '{named_input_requirement.concept.code}', falling back to TextContent",+ f"concept '{named_stuff_spec.concept.code}', falling back to TextContent",)- text_typed_named_input_requirement = TypedNamedInputRequirement.make_from_named(- named=named_input_requirement,+ text_typed_named_stuff_spec = TypedNamedStuffSpec.make_from_named(+ named=named_stuff_spec,structure_class=TextContent,)- needed_inputs_for_factory.append(text_typed_named_input_requirement)+ needed_inputs_for_factory.append(text_typed_named_stuff_spec)except Exception as exc:# Fallback to TextContent for any errors- log.warning(f"Error getting structure class for concept '{named_input_requirement.concept.code}': {exc}, falling back to TextContent")- text_typed_named_input_requirement = TypedNamedInputRequirement.make_from_named(- named=named_input_requirement,+ log.warning(f"Error getting structure class for concept '{named_stuff_spec.concept.code}': {exc}, falling back to TextContent")+ text_typed_named_stuff_spec = TypedNamedStuffSpec.make_from_named(+ named=named_stuff_spec,structure_class=TextContent,)- needed_inputs_for_factory.append(text_typed_named_input_requirement)+ needed_inputs_for_factory.append(text_typed_named_stuff_spec)return needed_inputs_for_factorydiff --git a/pipelex/pipe_run/exceptions.py b/pipelex/pipe_run/exceptions.pyindex cd1a0dc44..6bdbb538d 100644--- a/pipelex/pipe_run/exceptions.py+++ b/pipelex/pipe_run/exceptions.py@@ -11,8 +11,9 @@ class BatchParamsError(PipelexError):class PipeRunError(PipelexError):- def __init__(self, message: str, run_mode: PipeRunMode):+ def __init__(self, message: str, run_mode: PipeRunMode, pipe_code: str):self.run_mode = run_mode+ self.pipe_code = pipe_codesuper().__init__(message)diff --git a/pipelex/tools/misc/markdown_utils.py b/pipelex/tools/misc/markdown_utils.pyindex d0f69ee9d..50877bf1e 100644--- a/pipelex/tools/misc/markdown_utils.py+++ b/pipelex/tools/misc/markdown_utils.py@@ -13,13 +13,13 @@ def convert_to_markdown(data: Any, level: int = 1, is_pretty: bool = False, key:the_dict = cast("dict[str, Any]", data)# Treat keys as headings and values as their contentdict_result_lines: list[str] = []- for _key, _value in the_dict.items():+ for dict_key, dict_value in the_dict.items():heading_prefix = "#" * min(level, 6) # Limit heading levels to 6# Use the key as a heading- converted_line = f"{heading_prefix} {snake_to_capitalize_first_letter(_key)}" if is_pretty else f"{heading_prefix} {_key}"+ converted_line = f"{heading_prefix} {snake_to_capitalize_first_letter(dict_key)}" if is_pretty else f"{heading_prefix} {dict_key}"# Convert the value recursively, increasing the heading level# dict_result_lines.append(convert_to_markdown(data=value, level=level + 1))- converted_value = convert_to_markdown(data=_value, level=level + 1, key=_key)+ converted_value = convert_to_markdown(data=dict_value, level=level + 1, key=dict_key)converted_value_nb_lines = len(converted_value.split("\n"))if converted_value_nb_lines > 1:dict_result_lines.append(converted_line)diff --git a/tests/e2e/pipelex/pipes/pipe_controller/pipe_condition/test_pipe_condition_simple.py b/tests/e2e/pipelex/pipes/pipe_controller/pipe_condition/test_pipe_condition_simple.pyindex 082f51214..c9ab487c7 100644--- a/tests/e2e/pipelex/pipes/pipe_controller/pipe_condition/test_pipe_condition_simple.py+++ b/tests/e2e/pipelex/pipes/pipe_controller/pipe_condition/test_pipe_condition_simple.py@@ -9,7 +9,7 @@ from pipelex.core.concepts.native.concept_native import NativeConceptCodefrom pipelex.core.domains.domain import SpecialDomainfrom pipelex.core.memory.working_memory_factory import WorkingMemoryFactoryfrom pipelex.core.pipes.inputs.exceptions import PipeRunInputsError-from pipelex.core.pipes.inputs.input_requirements import TypedNamedInputRequirement+from pipelex.core.pipes.inputs.input_stuff_specs import TypedNamedStuffSpecfrom pipelex.core.pipes.pipe_factory import PipeFactoryfrom pipelex.pipe_controllers.condition.pipe_condition import PipeConditionfrom pipelex.pipe_controllers.condition.pipe_condition_blueprint import PipeConditionBlueprint@@ -81,7 +81,7 @@ class TestPipeConditionSimple:# Test with proper working memory - should SUCCEED or fail at expression evaluation (not missing inputs)working_memory = WorkingMemoryFactory.make_for_dry_run(needed_inputs=[- TypedNamedInputRequirement(+ TypedNamedStuffSpec(variable_name="user_status",concept=ConceptFactory.make(concept_code="CategoryInput",diff --git a/tests/e2e/pipelex/pipes/pipe_controller/pipe_sequence/test_pipe_sequence_batching.py b/tests/e2e/pipelex/pipes/pipe_controller/pipe_sequence/test_pipe_sequence_batching.pyindex b37aeee31..018a44e47 100644--- a/tests/e2e/pipelex/pipes/pipe_controller/pipe_sequence/test_pipe_sequence_batching.py+++ b/tests/e2e/pipelex/pipes/pipe_controller/pipe_sequence/test_pipe_sequence_batching.py@@ -8,7 +8,7 @@ import pytestfrom pipelex import logfrom pipelex.core.concepts.concept_factory import ConceptFactoryfrom pipelex.core.memory.working_memory_factory import WorkingMemoryFactory-from pipelex.core.pipes.inputs.input_requirements import TypedNamedInputRequirement+from pipelex.core.pipes.inputs.input_stuff_specs import TypedNamedStuffSpecfrom pipelex.core.stuffs.stuff_factory import StuffFactoryfrom pipelex.hub import get_required_pipefrom pipelex.pipe_run.pipe_run_params import PipeRunMode@@ -28,7 +28,7 @@ async def test_review_analysis_sequence_with_batching(pipe_run_mode: PipeRunModeif pipe_run_mode == PipeRunMode.DRY:working_memory = WorkingMemoryFactory.make_for_dry_run(needed_inputs=[- TypedNamedInputRequirement(+ TypedNamedStuffSpec(variable_name="document",concept=ConceptFactory.make(concept_code="Document",diff --git a/tests/integration/pipelex/pipes/controller/pipe_condition/test_pipe_condition_complex.py b/tests/integration/pipelex/pipes/controller/pipe_condition/test_pipe_condition_complex.pyindex 94311457e..a248b04ce 100644--- a/tests/integration/pipelex/pipes/controller/pipe_condition/test_pipe_condition_complex.py+++ b/tests/integration/pipelex/pipes/controller/pipe_condition/test_pipe_condition_complex.py@@ -13,6 +13,7 @@ from pipelex.core.pipes.inputs.exceptions import PipeRunInputsErrorfrom pipelex.core.stuffs.stuff_factory import StuffFactoryfrom pipelex.core.stuffs.text_content import TextContentfrom pipelex.hub import get_pipe_router, get_required_pipe+from pipelex.pipe_run.exceptions import PipeRouterErrorfrom pipelex.pipe_run.pipe_job_factory import PipeJobFactoryfrom pipelex.pipe_run.pipe_run_params import PipeRunModefrom pipelex.pipe_run.pipe_run_params_factory import PipeRunParamsFactory@@ -287,7 +288,7 @@ class TestPipeConditionComplex:working_memory = WorkingMemoryFactory.make_from_single_stuff(doc_stuff)- with pytest.raises(PipeRunInputsError) as exc_info:+ with pytest.raises(PipeRouterError) as exc_info:await get_pipe_router().run(pipe_job=PipeJobFactory.make_pipe_job(pipe=get_required_pipe(pipe_code="complex_document_processor"),@@ -299,10 +300,14 @@ class TestPipeConditionComplex:error = exc_info.valueassert error.pipe_code == "complex_document_processor"- assert error.missing_inputs is not None- assert "user_profile" in error.missing_inputsassert "Missing required inputs" in str(error)+ # Check the underlying cause is PipeRunInputsError with missing_inputs details+ cause = error.__cause__+ assert isinstance(cause, PipeRunInputsError)+ assert cause.missing_inputs is not None+ assert "user_profile" in cause.missing_inputs+@pytest.mark.parametrize(("doc_type", "priority", "user_level", "department", "complexity", "language", "expected_output_contains"),[diff --git a/tests/integration/pipelex/pipes/controller/pipe_condition/test_pipe_condition_simple.py b/tests/integration/pipelex/pipes/controller/pipe_condition/test_pipe_condition_simple.pyindex 7acbe3202..c58fabc25 100644--- a/tests/integration/pipelex/pipes/controller/pipe_condition/test_pipe_condition_simple.py+++ b/tests/integration/pipelex/pipes/controller/pipe_condition/test_pipe_condition_simple.py@@ -16,6 +16,7 @@ from pipelex.hub import get_pipe_router, get_required_pipefrom pipelex.pipe_controllers.condition.pipe_condition import PipeConditionfrom pipelex.pipe_controllers.condition.pipe_condition_blueprint import PipeConditionBlueprintfrom pipelex.pipe_controllers.condition.special_outcome import SpecialOutcome+from pipelex.pipe_run.exceptions import PipeRouterErrorfrom pipelex.pipe_run.pipe_job_factory import PipeJobFactoryfrom pipelex.pipe_run.pipe_run_params import PipeRunModefrom pipelex.pipe_run.pipe_run_params_factory import PipeRunParamsFactory@@ -222,7 +223,7 @@ class TestPipeConditionSimple:empty_working_memory = WorkingMemoryFactory.make_empty()# Run dry run using the real pipe - this should fail with PipeRouterError- with pytest.raises(PipeRunInputsError) as exc_info:+ with pytest.raises(PipeRouterError) as exc_info:await get_pipe_router().run(pipe_job=PipeJobFactory.make_pipe_job(pipe=get_required_pipe(pipe_code="basic_condition_by_category_2"),@@ -235,10 +236,14 @@ class TestPipeConditionSimple:# Verify the error detailserror = exc_info.valueassert error.pipe_code == "basic_condition_by_category_2"- assert error.missing_inputs is not None- assert "input_data" in error.missing_inputsassert "Missing required inputs" in str(error)+ # Check the underlying cause is PipeRunInputsError with missing_inputs details+ cause = error.__cause__+ assert isinstance(cause, PipeRunInputsError)+ assert cause.missing_inputs is not None+ assert "input_data" in cause.missing_inputs+async def test_condition_dry_run_medium_category_validation(self, load_test_library: Callable[[list[Path]], None]):"""Test PipeCondition dry run with medium category - should validate the 'medium' branch."""load_test_library([Path("tests/integration/pipelex/pipes/controller/pipe_condition")])diff --git a/tests/integration/pipelex/pipes/controller/pipe_parallel/test_pipe_parallel_validation.py b/tests/integration/pipelex/pipes/controller/pipe_parallel/test_pipe_parallel_validation.pyindex 97ba2a7a1..b7ffbfe07 100644--- a/tests/integration/pipelex/pipes/controller/pipe_parallel/test_pipe_parallel_validation.py+++ b/tests/integration/pipelex/pipes/controller/pipe_parallel/test_pipe_parallel_validation.py@@ -2,7 +2,7 @@ from typing import Callablefrom pipelex.core.concepts.concept_blueprint import ConceptBlueprintfrom pipelex.core.concepts.concept_factory import ConceptFactory-from pipelex.core.pipes.inputs.input_requirements import InputRequirements+from pipelex.core.pipes.inputs.input_stuff_specs import InputStuffSpecsfrom pipelex.core.pipes.pipe_factory import PipeFactoryfrom pipelex.hub import get_concept_library, get_pipe_libraryfrom pipelex.pipe_controllers.parallel.pipe_parallel import PipeParallel@@ -60,8 +60,8 @@ class TestPipeParallelValidation:# Verify the real pipe was created successfullyassert real_pipe.domain == domain- assert real_pipe.output.code == concept_3.code- assert real_pipe.output.domain == domain+ assert real_pipe.output.concept.code == concept_3.code+ assert real_pipe.output.concept.domain == domain# Create PipeParallel that would reference this pipepipe_parallel_blueprint = PipeParallelBlueprint(@@ -140,8 +140,8 @@ class TestPipeParallelValidation:assert pipe_parallel.domain == domainassert len(pipe_parallel.parallel_sub_pipes) == 1assert pipe_parallel.inputs.root["input_var"].concept.code == concept_1.code- assert pipe_parallel.output.code == concept_3.code- assert pipe_parallel.output.domain == domain+ assert pipe_parallel.output.concept.code == concept_3.code+ assert pipe_parallel.output.concept.domain == domainassert pipe_parallel.add_each_output is Trueassert pipe_parallel.combined_output is None@@ -193,8 +193,8 @@ class TestPipeParallelValidation:# Test that needed_inputs method can be calledneeded_inputs = pipe_parallel.needed_inputs()- # Verify it returns a PipeInput object- assert isinstance(needed_inputs, InputRequirements)+ # Verify it returns a InputStuffSpecs object+ assert isinstance(needed_inputs, InputStuffSpecs)assert hasattr(needed_inputs, "root")assert isinstance(needed_inputs.root, dict)# With no sub-pipes, should return empty inputsdiff --git a/tests/integration/pipelex/pipes/controller/pipe_sequence/test_pipe_sequence_output_multiplicity.py b/tests/integration/pipelex/pipes/controller/pipe_sequence/test_pipe_sequence_output_multiplicity.pynew file mode 100644index 000000000..8d0ea61d6--- /dev/null+++ b/tests/integration/pipelex/pipes/controller/pipe_sequence/test_pipe_sequence_output_multiplicity.py@@ -0,0 +1,275 @@+"""Test for PipeSequence output multiplicity validation."""++from typing import Callable++import pytest++from pipelex.core.pipes.exceptions import PipeValidationError+from pipelex.core.pipes.pipe_factory import PipeFactory+from pipelex.hub import get_pipe_library+from pipelex.pipe_controllers.sequence.pipe_sequence import PipeSequence+from pipelex.pipe_controllers.sequence.pipe_sequence_blueprint import PipeSequenceBlueprint+from pipelex.pipe_controllers.sub_pipe_blueprint import SubPipeBlueprint+from pipelex.pipe_operators.llm.pipe_llm import PipeLLM+from pipelex.pipe_operators.llm.pipe_llm_blueprint import PipeLLMBlueprint+++class TestPipeSequenceOutputMultiplicity:+ """Test that PipeSequence validates output multiplicity matches the last step."""++ def test_multiplicity_mismatch_raises_error(+ self,+ load_empty_library: Callable[[], str],+ ):+ """Test that validation fails when sequence output multiplicity doesn't match last step.++ Creates:+ - A PipeLLM with output_multiplicity=3 (output="Text[3]")+ - A PipeSequence with output_multiplicity=None (output="Text")+ The validation should fail because multiplicities don't match.+ """+ load_empty_library()++ domain = "test_multiplicity"++ # Create a PipeLLM with multiple output (output_multiplicity=3)+ llm_blueprint = PipeLLMBlueprint(+ description="LLM that outputs multiple",+ inputs={"input_text": "Text"},+ output="Text[3]", # Multiple output+ model="llm_for_testing_gen_text",+ prompt="@input_text",+ )+ llm_pipe = PipeFactory[PipeLLM].make_from_blueprint(+ domain_code=domain,+ pipe_code="llm_multiple_output",+ blueprint=llm_blueprint,+ )+ get_pipe_library().add_new_pipe(llm_pipe)++ # Create a PipeSequence with single output (output_multiplicity=None)+ sequence_blueprint = PipeSequenceBlueprint(+ description="Sequence with single output",+ inputs={"input_text": "Text"},+ output="Text", # Single output - MISMATCH!+ steps=[+ SubPipeBlueprint(pipe="llm_multiple_output", result="result"),+ ],+ )+ sequence_pipe = PipeFactory[PipeSequence].make_from_blueprint(+ domain_code=domain,+ pipe_code="sequence_mismatch",+ blueprint=sequence_blueprint,+ )+ get_pipe_library().add_new_pipe(sequence_pipe)++ # Validation should fail due to multiplicity mismatch+ with pytest.raises(PipeValidationError) as exc_info:+ sequence_pipe.validate_with_libraries()++ error_message = str(exc_info.value).lower()+ assert "multiplicity" in error_message, f"Error should mention multiplicity mismatch, got: {exc_info.value}"++ def test_no_multiplicity_matching_passes(+ self,+ load_empty_library: Callable[[], str],+ ):+ """Test that validation passes when both sequence and last step have no multiplicity.++ Creates:+ - A PipeLLM with output="Text" (no multiplicity)+ - A PipeSequence with output="Text" (no multiplicity)+ The validation should pass because multiplicities match (both None).+ """+ load_empty_library()++ domain = "test_no_multiplicity"++ # Create a PipeLLM with single output (no multiplicity)+ llm_blueprint = PipeLLMBlueprint(+ description="LLM with single output",+ inputs={"input_text": "Text"},+ output="Text", # Single output+ model="llm_for_testing_gen_text",+ prompt="@input_text",+ )+ llm_pipe = PipeFactory[PipeLLM].make_from_blueprint(+ domain_code=domain,+ pipe_code="llm_single_output",+ blueprint=llm_blueprint,+ )+ get_pipe_library().add_new_pipe(llm_pipe)++ # Create a PipeSequence with single output (no multiplicity) - MATCHES+ sequence_blueprint = PipeSequenceBlueprint(+ description="Sequence with single output",+ inputs={"input_text": "Text"},+ output="Text", # Single output - MATCHES!+ steps=[+ SubPipeBlueprint(pipe="llm_single_output", result="result"),+ ],+ )+ sequence_pipe = PipeFactory[PipeSequence].make_from_blueprint(+ domain_code=domain,+ pipe_code="sequence_matching",+ blueprint=sequence_blueprint,+ )+ get_pipe_library().add_new_pipe(sequence_pipe)++ # Validation should pass - no exception raised+ sequence_pipe.validate_with_libraries()++ def test_variable_multiplicity_matching_passes(+ self,+ load_empty_library: Callable[[], str],+ ):+ """Test that validation passes when both have variable multiplicity [].++ Creates:+ - A PipeLLM with output="Text[]" (variable multiplicity)+ - A PipeSequence with output="Text[]" (variable multiplicity)+ The validation should pass because multiplicities match (both True).+ """+ load_empty_library()++ domain = "test_variable_multiplicity"++ # Create a PipeLLM with variable multiplicity output+ llm_blueprint = PipeLLMBlueprint(+ description="LLM with variable output",+ inputs={"input_text": "Text"},+ output="Text[]", # Variable multiplicity+ model="llm_for_testing_gen_text",+ prompt="@input_text",+ )+ llm_pipe = PipeFactory[PipeLLM].make_from_blueprint(+ domain_code=domain,+ pipe_code="llm_variable_output",+ blueprint=llm_blueprint,+ )+ get_pipe_library().add_new_pipe(llm_pipe)++ # Create a PipeSequence with variable multiplicity - MATCHES+ sequence_blueprint = PipeSequenceBlueprint(+ description="Sequence with variable output",+ inputs={"input_text": "Text"},+ output="Text[]", # Variable multiplicity - MATCHES!+ steps=[+ SubPipeBlueprint(pipe="llm_variable_output", result="result"),+ ],+ )+ sequence_pipe = PipeFactory[PipeSequence].make_from_blueprint(+ domain_code=domain,+ pipe_code="sequence_variable_matching",+ blueprint=sequence_blueprint,+ )+ get_pipe_library().add_new_pipe(sequence_pipe)++ # Validation should pass - no exception raised+ sequence_pipe.validate_with_libraries()++ def test_variable_vs_none_multiplicity_mismatch(+ self,+ load_empty_library: Callable[[], str],+ ):+ """Test that validation fails when last step has [] but sequence has none.++ Creates:+ - A PipeLLM with output="Text[]" (variable multiplicity)+ - A PipeSequence with output="Text" (no multiplicity)+ The validation should fail because multiplicities don't match.+ """+ load_empty_library()++ domain = "test_variable_vs_none"++ # Create a PipeLLM with variable multiplicity+ llm_blueprint = PipeLLMBlueprint(+ description="LLM with variable output",+ inputs={"input_text": "Text"},+ output="Text[]", # Variable multiplicity+ model="llm_for_testing_gen_text",+ prompt="@input_text",+ )+ llm_pipe = PipeFactory[PipeLLM].make_from_blueprint(+ domain_code=domain,+ pipe_code="llm_variable",+ blueprint=llm_blueprint,+ )+ get_pipe_library().add_new_pipe(llm_pipe)++ # Create a PipeSequence with no multiplicity - MISMATCH+ sequence_blueprint = PipeSequenceBlueprint(+ description="Sequence with single output",+ inputs={"input_text": "Text"},+ output="Text", # No multiplicity - MISMATCH!+ steps=[+ SubPipeBlueprint(pipe="llm_variable", result="result"),+ ],+ )+ sequence_pipe = PipeFactory[PipeSequence].make_from_blueprint(+ domain_code=domain,+ pipe_code="sequence_mismatch_var_none",+ blueprint=sequence_blueprint,+ )+ get_pipe_library().add_new_pipe(sequence_pipe)++ # Validation should fail due to multiplicity mismatch+ with pytest.raises(PipeValidationError) as exc_info:+ sequence_pipe.validate_with_libraries()++ error_message = str(exc_info.value).lower()+ assert "multiplicity" in error_message, f"Error should mention multiplicity mismatch, got: {exc_info.value}"++ def test_fixed_vs_variable_multiplicity_mismatch(+ self,+ load_empty_library: Callable[[], str],+ ):+ """Test that validation fails when last step has [3] but sequence has [].++ Creates:+ - A PipeLLM with output="Text[3]" (fixed multiplicity)+ - A PipeSequence with output="Text[]" (variable multiplicity)+ The validation should fail because multiplicities don't match (3 vs True).+ """+ load_empty_library()++ domain = "test_fixed_vs_variable"++ # Create a PipeLLM with fixed multiplicity+ llm_blueprint = PipeLLMBlueprint(+ description="LLM with fixed output count",+ inputs={"input_text": "Text"},+ output="Text[3]", # Fixed multiplicity of 3+ model="llm_for_testing_gen_text",+ prompt="@input_text",+ )+ llm_pipe = PipeFactory[PipeLLM].make_from_blueprint(+ domain_code=domain,+ pipe_code="llm_fixed_3",+ blueprint=llm_blueprint,+ )+ get_pipe_library().add_new_pipe(llm_pipe)++ # Create a PipeSequence with variable multiplicity - MISMATCH+ sequence_blueprint = PipeSequenceBlueprint(+ description="Sequence with variable output",+ inputs={"input_text": "Text"},+ output="Text[]", # Variable multiplicity - MISMATCH!+ steps=[+ SubPipeBlueprint(pipe="llm_fixed_3", result="result"),+ ],+ )+ sequence_pipe = PipeFactory[PipeSequence].make_from_blueprint(+ domain_code=domain,+ pipe_code="sequence_mismatch_fixed_var",+ blueprint=sequence_blueprint,+ )+ get_pipe_library().add_new_pipe(sequence_pipe)++ # Validation should fail due to multiplicity mismatch+ with pytest.raises(PipeValidationError) as exc_info:+ sequence_pipe.validate_with_libraries()++ error_message = str(exc_info.value).lower()+ assert "multiplicity" in error_message, f"Error should mention multiplicity mismatch, got: {exc_info.value}"diff --git a/tests/integration/pipelex/pipes/test_bracket_notation_controllers.py b/tests/integration/pipelex/pipes/test_bracket_notation_controllers.pyindex 46fdf5f55..c02b93793 100644--- a/tests/integration/pipelex/pipes/test_bracket_notation_controllers.py+++ b/tests/integration/pipelex/pipes/test_bracket_notation_controllers.py@@ -51,7 +51,7 @@ class TestBracketNotationInControllers:)assert pipe.inputs.root["data"].multiplicity == 2- assert pipe.output.code == "ProcessedData"+ assert pipe.output.concept.code == "ProcessedData"concept_library.teardown()@@ -90,7 +90,7 @@ class TestBracketNotationInControllers:)assert pipe.inputs.root["items"].multiplicity is True- assert pipe.output.code == "Result"+ assert pipe.output.concept.code == "Result"concept_library.teardown()@@ -129,6 +129,6 @@ class TestBracketNotationInControllers:)assert pipe.inputs.root["items"].multiplicity is True- assert pipe.output.code == "ProcessedItem"+ assert pipe.output.concept.code == "ProcessedItem"concept_library.teardown()diff --git a/tests/integration/pipelex/pipes/test_bracket_notation_operators/test_bracket_notation_operators.py b/tests/integration/pipelex/pipes/test_bracket_notation_operators/test_bracket_notation_operators.pyindex 70180f5ba..4cfd80ff2 100644--- a/tests/integration/pipelex/pipes/test_bracket_notation_operators/test_bracket_notation_operators.py+++ b/tests/integration/pipelex/pipes/test_bracket_notation_operators/test_bracket_notation_operators.py@@ -49,7 +49,7 @@ class TestBracketNotationInOperators:blueprint=blueprint,)- assert pipe.output.code == "Text"+ assert pipe.output.concept.code == "Text"assert pipe.output_multiplicity is Truedef test_pipe_llm_with_bracket_output_fixed_count(self, load_empty_library: Callable[[], None]):@@ -68,7 +68,7 @@ class TestBracketNotationInOperators:blueprint=blueprint,)- assert pipe.output.code == "Text"+ assert pipe.output.concept.code == "Text"assert pipe.output_multiplicity == 5def test_pipe_llm_with_bracket_inputs(self, load_empty_library: Callable[[], None]):@@ -108,7 +108,7 @@ class TestBracketNotationInOperators:blueprint=blueprint,)- assert pipe.output.code == "Image"+ assert pipe.output.concept.code == "Image"assert pipe.output_multiplicity == 3def test_pipe_func_with_bracket_input_and_output(self, load_test_library: Callable[[list[Path]], None]):@@ -128,7 +128,7 @@ class TestBracketNotationInOperators:)assert pipe.inputs.root["two_texts"].multiplicity == 2- assert pipe.output.code == "Text"+ assert pipe.output.concept.code == "Text"def test_pipe_compose_with_bracket_notation(self, load_empty_library: Callable[[], None]):load_empty_library()@@ -147,7 +147,7 @@ class TestBracketNotationInOperators:)assert pipe.inputs.root["items"].multiplicity is True- assert pipe.output.code == "Text"+ assert pipe.output.concept.code == "Text"def test_pipe_extract_with_bracket_output(self, load_empty_library: Callable[[], None]):load_empty_library()@@ -164,4 +164,4 @@ class TestBracketNotationInOperators:blueprint=blueprint,)- assert pipe.output.code == "Page"+ assert pipe.output.concept.code == "Page"diff --git a/tests/unit/pipelex/builder/test_runner_generator.py b/tests/unit/pipelex/builder/test_runner_generator.pyindex dfc01f031..326ded71f 100644--- a/tests/unit/pipelex/builder/test_runner_generator.py+++ b/tests/unit/pipelex/builder/test_runner_generator.py@@ -11,7 +11,8 @@ from pipelex.builder.runner_code import generate_runner_codefrom pipelex.core.concepts.concept_factory import ConceptFactoryfrom pipelex.core.concepts.concept_representation_generator import ConceptRepresentationFormatfrom pipelex.core.concepts.native.concept_native import NativeConceptCode-from pipelex.core.pipes.inputs.input_requirements import InputRequirement, InputRequirements+from pipelex.core.pipes.inputs.input_stuff_specs import InputStuffSpecs+from pipelex.core.pipes.stuff_spec.stuff_spec import StuffSpecclass TestConceptGenerateInputRepresentationJson:@@ -97,19 +98,19 @@ class TestConceptGenerateInputRepresentationPython:assert "PDFContent" in imports-class TestInputRequirementsGenerateJsonRepresentation:- """Test InputRequirements.generate_json_representation method."""+class TestInputStuffSpecsGenerateJsonRepresentation:+ """Test InputStuffSpecs.generate_json_representation method."""def test_empty_inputs(self) -> None:"""Test JSON generation with no inputs."""- inputs = InputRequirements(root={})+ inputs = InputStuffSpecs(root={})result = inputs.generate_json_representation()assert result == {}def test_single_input(self) -> None:"""Test JSON generation with a single input."""concept = ConceptFactory.make_native_concept(NativeConceptCode.TEXT)- inputs = InputRequirements(root={"message": InputRequirement(concept=concept)})+ inputs = InputStuffSpecs(root={"message": StuffSpec(concept=concept)})result = inputs.generate_json_representation()assert "message" in resultassert result["message"]["concept"] == "native.Text"@@ -118,10 +119,10 @@ class TestInputRequirementsGenerateJsonRepresentation:"""Test JSON generation with multiple inputs."""text_concept = ConceptFactory.make_native_concept(NativeConceptCode.TEXT)image_concept = ConceptFactory.make_native_concept(NativeConceptCode.IMAGE)- inputs = InputRequirements(+ inputs = InputStuffSpecs(root={- "text_input": InputRequirement(concept=text_concept),- "image_input": InputRequirement(concept=image_concept),+ "text_input": StuffSpec(concept=text_concept),+ "image_input": StuffSpec(concept=image_concept),})result = inputs.generate_json_representation()@@ -131,13 +132,13 @@ class TestInputRequirementsGenerateJsonRepresentation:assert result["image_input"]["concept"] == "native.Image"-class TestInputRequirementsJsonWithMultiplicity:- """Test InputRequirements.generate_json_representation with multiplicity - content is wrapped in list."""+class TestInputStuffSpecsJsonWithMultiplicity:+ """Test InputStuffSpecs.generate_json_representation with multiplicity - content is wrapped in list."""def test_single_item_no_multiplicity(self) -> None:"""Test that single item (no multiplicity) has content as dict, not list."""concept = ConceptFactory.make_native_concept(NativeConceptCode.PDF)- inputs = InputRequirements(root={"document": InputRequirement(concept=concept, multiplicity=None)})+ inputs = InputStuffSpecs(root={"document": StuffSpec(concept=concept, multiplicity=None)})result = inputs.generate_json_representation()assert "document" in result# concept should be present@@ -150,7 +151,7 @@ class TestInputRequirementsJsonWithMultiplicity:def test_multiple_items_true_multiplicity(self) -> None:"""Test that multiplicity=True wraps content in list."""concept = ConceptFactory.make_native_concept(NativeConceptCode.PDF)- inputs = InputRequirements(root={"documents": InputRequirement(concept=concept, multiplicity=True)})+ inputs = InputStuffSpecs(root={"documents": StuffSpec(concept=concept, multiplicity=True)})result = inputs.generate_json_representation()assert "documents" in result# concept should be at the top level@@ -164,7 +165,7 @@ class TestInputRequirementsJsonWithMultiplicity:def test_multiple_items_int_multiplicity(self) -> None:"""Test that multiplicity=N (int > 1) wraps content in list."""concept = ConceptFactory.make_native_concept(NativeConceptCode.IMAGE)- inputs = InputRequirements(root={"images": InputRequirement(concept=concept, multiplicity=3)})+ inputs = InputStuffSpecs(root={"images": StuffSpec(concept=concept, multiplicity=3)})result = inputs.generate_json_representation()assert "images" in result# concept should be at the top level@@ -178,10 +179,10 @@ class TestInputRequirementsJsonWithMultiplicity:def test_mixed_multiplicity(self) -> None:"""Test mixed single and multiple inputs."""pdf_concept = ConceptFactory.make_native_concept(NativeConceptCode.PDF)- inputs = InputRequirements(+ inputs = InputStuffSpecs(root={- "single_pdf": InputRequirement(concept=pdf_concept, multiplicity=None),- "multiple_pdfs": InputRequirement(concept=pdf_concept, multiplicity=True),+ "single_pdf": StuffSpec(concept=pdf_concept, multiplicity=None),+ "multiple_pdfs": StuffSpec(concept=pdf_concept, multiplicity=True),})result = inputs.generate_json_representation()@@ -202,8 +203,8 @@ class TestGenerateRunnerCode:mock_pipe = MagicMock()mock_pipe.code = "test_pipe"- mock_pipe.output = text_concept- mock_pipe.inputs = InputRequirements(root={"document": InputRequirement(concept=pdf_concept)})+ mock_pipe.output = StuffSpec(concept=text_concept)+ mock_pipe.inputs = InputStuffSpecs(root={"document": StuffSpec(concept=pdf_concept)})return mock_pipe@pytest.fixture@@ -214,8 +215,8 @@ class TestGenerateRunnerCode:mock_pipe = MagicMock()mock_pipe.code = "test_pipe_list"- mock_pipe.output = text_concept- mock_pipe.inputs = InputRequirements(root={"documents": InputRequirement(concept=pdf_concept, multiplicity=True)})+ mock_pipe.output = StuffSpec(concept=text_concept)+ mock_pipe.inputs = InputStuffSpecs(root={"documents": StuffSpec(concept=pdf_concept, multiplicity=True)})return mock_pipedef test_runner_code_includes_imports(self, mock_pipe_single_output: MagicMock) -> None:@@ -276,8 +277,8 @@ class TestGenerateRunnerCode:mock_pipe = MagicMock()mock_pipe.code = "custom_pipe"- mock_pipe.output = custom_concept- mock_pipe.inputs = InputRequirements(root={"document": InputRequirement(concept=pdf_concept)})+ mock_pipe.output = StuffSpec(concept=custom_concept)+ mock_pipe.inputs = InputStuffSpecs(root={"document": StuffSpec(concept=pdf_concept)})runner_code = generate_runner_code(mock_pipe)# Custom imports should NOT use relative import (no leading dot) for standalone scriptsdiff --git a/tests/unit/pipelex/core/memory/test_dry_working_memory.py b/tests/unit/pipelex/core/memory/test_dry_working_memory.pyindex 833868012..680a99be2 100644--- a/tests/unit/pipelex/core/memory/test_dry_working_memory.py+++ b/tests/unit/pipelex/core/memory/test_dry_working_memory.py@@ -4,7 +4,7 @@ from pipelex import logfrom pipelex.core.concepts.concept_factory import ConceptFactoryfrom pipelex.core.concepts.native.concept_native import NativeConceptCodefrom pipelex.core.memory.working_memory_factory import WorkingMemoryFactory-from pipelex.core.pipes.inputs.input_requirements import TypedNamedInputRequirement+from pipelex.core.pipes.inputs.input_stuff_specs import TypedNamedStuffSpecfrom pipelex.core.stuffs.page_content import PageContentfrom pipelex.core.stuffs.text_content import TextContentfrom tests.unit.pipelex.core.memory.tricky_questions import ThoughtfulAnswer@@ -21,7 +21,7 @@ class TestDryWorkingMemory:# Test the specific inputs requested by the userneeded_inputs = [- TypedNamedInputRequirement(+ TypedNamedStuffSpec(variable_name="page",concept=ConceptFactory.make(concept_code=NativeConceptCode.PAGE, domain="test_tricky_questions", description="Lorem Ipsum", structure_class_name="Page"@@ -62,7 +62,7 @@ class TestDryWorkingMemory:# Use ThoughtfulAnswer from tricky questions domainneeded_inputs = [- TypedNamedInputRequirement(+ TypedNamedStuffSpec(variable_name="thoughtful_answer",concept=ConceptFactory.make(concept_code="ThoughtfulAnswer",@@ -72,7 +72,7 @@ class TestDryWorkingMemory:),structure_class=ThoughtfulAnswer,),- TypedNamedInputRequirement(+ TypedNamedStuffSpec(variable_name="question",concept=ConceptFactory.make(concept_code="Question", domain="answer", description="Question", structure_class_name="Question"),structure_class=TextContent,@@ -119,7 +119,7 @@ class TestDryWorkingMemory:log.info("Testing dry run with TextContent fallback")needed_inputs = [- TypedNamedInputRequirement(+ TypedNamedStuffSpec(variable_name="question_analysis",concept=ConceptFactory.make(concept_code="QuestionAnalysis",@@ -129,7 +129,7 @@ class TestDryWorkingMemory:),structure_class=TextContent,),- TypedNamedInputRequirement(+ TypedNamedStuffSpec(variable_name="conclusion",concept=ConceptFactory.make(concept_code="ThoughtfulAnswerConclusion",@@ -167,7 +167,7 @@ class TestDryWorkingMemory:log.info("Testing dry run with mixed content types")needed_inputs = [- TypedNamedInputRequirement(+ TypedNamedStuffSpec(variable_name="thoughtful_answer",concept=ConceptFactory.make(concept_code="ThoughtfulAnswer",@@ -177,12 +177,12 @@ class TestDryWorkingMemory:),structure_class=ThoughtfulAnswer,),- TypedNamedInputRequirement(+ TypedNamedStuffSpec(variable_name="raw_question",concept=ConceptFactory.make(concept_code="Question", domain="answer", description="Question", structure_class_name="Question"),structure_class=TextContent,),- TypedNamedInputRequirement(+ TypedNamedStuffSpec(variable_name="analysis_result",concept=ConceptFactory.make(concept_code="QuestionAnalysis",@@ -224,7 +224,7 @@ class TestDryWorkingMemory:):log.info("Testing dry run with empty inputs")- needed_inputs: list[TypedNamedInputRequirement] = []+ needed_inputs: list[TypedNamedStuffSpec] = []dry_memory = WorkingMemoryFactory.make_for_dry_run(needed_inputs=needed_inputs)@@ -240,12 +240,12 @@ class TestDryWorkingMemory:# Simulate the conclude_tricky_question_by_steps pipeline needsneeded_inputs = [- TypedNamedInputRequirement(+ TypedNamedStuffSpec(variable_name="question",concept=ConceptFactory.make(concept_code="Question", domain="answer", description="Question", structure_class_name="Question"),structure_class=TextContent,),- TypedNamedInputRequirement(+ TypedNamedStuffSpec(variable_name="question_analysis",concept=ConceptFactory.make(concept_code="QuestionAnalysis",@@ -255,7 +255,7 @@ class TestDryWorkingMemory:),structure_class=TextContent,),- TypedNamedInputRequirement(+ TypedNamedStuffSpec(variable_name="thoughtful_answer",concept=ConceptFactory.make(concept_code="ThoughtfulAnswer",diff --git a/tests/unit/pipelex/core/pipes/test_input_requirements_factory.py b/tests/unit/pipelex/core/pipes/test_input_requirements_factory.pyindex cd6c25228..cbe37d3ff 100644--- a/tests/unit/pipelex/core/pipes/test_input_requirements_factory.py+++ b/tests/unit/pipelex/core/pipes/test_input_requirements_factory.py@@ -3,8 +3,8 @@ from typing import Callableimport pytestfrom pipelex.core.concepts.exceptions import ConceptStringError-from pipelex.core.pipes.inputs.input_requirements import InputRequirement-from pipelex.core.pipes.inputs.input_requirements_factory import InputRequirementsFactory, InputRequirementsFactoryError+from pipelex.core.pipes.inputs.input_stuff_specs_factory import InputStuffSpecsFactory, InputStuffSpecsFactoryError+from pipelex.core.pipes.stuff_spec.stuff_spec import StuffSpecfrom pipelex.libraries.concept.exceptions import ConceptLibraryErrorfrom tests.unit.pipelex.core.pipes.data import (CONCEPT_CODE_RESOLUTION_TEST_CASES,@@ -18,79 +18,79 @@ from tests.unit.pipelex.core.pipes.data import (class TestMakeInputRequirementsFromString:- """Test the InputRequirementsFactory.make_from_str method."""+ """Test the InputStuffSpecsFactory.make_from_str method."""@pytest.mark.parametrize(- ("domain", "requirement_str", "expected_concept_string", "expected_multiplicity"),+ ("domain", "stuff_spec_str", "expected_concept_string", "expected_multiplicity"),SINGLE_ITEM_NO_BRACKETS_TEST_CASES,)def test_single_item_default_no_brackets(self,domain: str,- requirement_str: str,+ stuff_spec_str: str,expected_concept_string: str,expected_multiplicity: int | bool | None,load_empty_library: Callable[[], None],):"""Test parsing a concept string without brackets (single item, default)."""load_empty_library()- result = InputRequirementsFactory.make_from_string(domain=domain, requirement_str=requirement_str)+ result = InputStuffSpecsFactory.make_from_string(domain=domain, stuff_spec_str=stuff_spec_str)- assert isinstance(result, InputRequirement)+ assert isinstance(result, StuffSpec)assert result.concept.concept_string == expected_concept_stringassert result.multiplicity == expected_multiplicity@pytest.mark.parametrize(- ("domain", "requirement_str", "expected_concept_string"),+ ("domain", "stuff_spec_str", "expected_concept_string"),MULTIPLE_ITEMS_EMPTY_BRACKETS_TEST_CASES,)def test_multiple_items_with_empty_brackets(- self, domain: str, requirement_str: str, expected_concept_string: str, load_empty_library: Callable[[], None]+ self, domain: str, stuff_spec_str: str, expected_concept_string: str, load_empty_library: Callable[[], None]):load_empty_library()"""Test parsing a concept string with empty brackets (multiple items)."""- result = InputRequirementsFactory.make_from_string(domain=domain, requirement_str=requirement_str)+ result = InputStuffSpecsFactory.make_from_string(domain=domain, stuff_spec_str=stuff_spec_str)- assert isinstance(result, InputRequirement)+ assert isinstance(result, StuffSpec)assert result.concept.concept_string == expected_concept_stringassert result.multiplicity is True@pytest.mark.parametrize(- ("domain", "requirement_str", "expected_concept_string", "expected_multiplicity"),+ ("domain", "stuff_spec_str", "expected_concept_string", "expected_multiplicity"),FIXED_COUNT_TEST_CASES,)def test_fixed_count_with_number_in_brackets(- self, domain: str, requirement_str: str, expected_concept_string: str, expected_multiplicity: int, load_empty_library: Callable[[], None]+ self, domain: str, stuff_spec_str: str, expected_concept_string: str, expected_multiplicity: int, load_empty_library: Callable[[], None]):"""Test parsing a concept string with a number in brackets (fixed count)."""load_empty_library()- result = InputRequirementsFactory.make_from_string(domain=domain, requirement_str=requirement_str)+ result = InputStuffSpecsFactory.make_from_string(domain=domain, stuff_spec_str=stuff_spec_str)- assert isinstance(result, InputRequirement)+ assert isinstance(result, StuffSpec)assert result.concept.concept_string == expected_concept_stringassert result.multiplicity == expected_multiplicity@pytest.mark.parametrize(- ("domain", "requirement_str", "expected_concept_string", "expected_multiplicity"),+ ("domain", "stuff_spec_str", "expected_concept_string", "expected_multiplicity"),VARIOUS_FIXED_COUNTS_TEST_CASES,)def test_various_fixed_counts(- self, domain: str, requirement_str: str, expected_concept_string: str, expected_multiplicity: int, load_empty_library: Callable[[], None]+ self, domain: str, stuff_spec_str: str, expected_concept_string: str, expected_multiplicity: int, load_empty_library: Callable[[], None]):load_empty_library()"""Test parsing concept strings with various numbers in brackets."""- result = InputRequirementsFactory.make_from_string(domain=domain, requirement_str=requirement_str)- assert result.multiplicity == expected_multiplicity, f"Failed for {requirement_str}"+ result = InputStuffSpecsFactory.make_from_string(domain=domain, stuff_spec_str=stuff_spec_str)+ assert result.multiplicity == expected_multiplicity, f"Failed for {stuff_spec_str}"assert result.concept.concept_string == expected_concept_string@pytest.mark.parametrize(- ("domain", "requirement_str", "expected_concept_string"),+ ("domain", "stuff_spec_str", "expected_concept_string"),DIFFERENT_CONCEPT_CODES_TEST_CASES,)- def test_different_concept_codes(self, domain: str, requirement_str: str, expected_concept_string: str, load_empty_library: Callable[[], None]):+ def test_different_concept_codes(self, domain: str, stuff_spec_str: str, expected_concept_string: str, load_empty_library: Callable[[], None]):load_empty_library()"""Test parsing various concept codes without multiplicity."""- result = InputRequirementsFactory.make_from_string(domain=domain, requirement_str=requirement_str)+ result = InputStuffSpecsFactory.make_from_string(domain=domain, stuff_spec_str=stuff_spec_str)assert result.concept.concept_string == expected_concept_stringassert result.multiplicity is None@@ -99,7 +99,7 @@ class TestMakeInputRequirementsFromString:"""Test parsing concept codes from custom domains."""# Note: This test will only work if these concepts exist in the system# For now, we'll test with native concepts, but the pattern should work for any domain- result = InputRequirementsFactory.make_from_string(domain="native", requirement_str="native.Text[3]")+ result = InputStuffSpecsFactory.make_from_string(domain="native", stuff_spec_str="native.Text[3]")assert result.concept.concept_string == "native.Text"assert result.multiplicity == 3@@ -107,19 +107,19 @@ class TestMakeInputRequirementsFromString:load_empty_library()"""Test that an invalid concept code raises ConceptLibraryConceptNotFoundError."""with pytest.raises(ConceptLibraryError):- InputRequirementsFactory.make_from_string(domain="nonexistent", requirement_str="nonexistent.InvalidConcept")+ InputStuffSpecsFactory.make_from_string(domain="nonexistent", stuff_spec_str="nonexistent.InvalidConcept")def test_concept_not_found_with_multiplicity_raises_error(self, load_empty_library: Callable[[], None]):load_empty_library()"""Test that an invalid concept code with multiplicity raises ConceptLibraryConceptNotFoundError."""with pytest.raises(ConceptLibraryError):- InputRequirementsFactory.make_from_string(domain="nonexistent", requirement_str="nonexistent.InvalidConcept[5]")+ InputStuffSpecsFactory.make_from_string(domain="nonexistent", stuff_spec_str="nonexistent.InvalidConcept[5]")def test_empty_string_raises_value_error(self, load_empty_library: Callable[[], None]):load_empty_library()- """Test that an empty string raises InputRequirementsFactorySyntaxError."""- with pytest.raises(InputRequirementsFactoryError, match="Invalid input requirement string") as exc_info:- InputRequirementsFactory.make_from_string(domain="native", requirement_str="")+ """Test that an empty string raises InputStuffSpecsFactorySyntaxError."""+ with pytest.raises(InputStuffSpecsFactoryError, match="Invalid input stuff spec string") as exc_info:+ InputStuffSpecsFactory.make_from_string(domain="native", stuff_spec_str="")# This error is raised directly without a causeassert exc_info.value.__cause__ is None@@ -128,30 +128,30 @@ class TestMakeInputRequirementsFromString:"""Test that brackets with non-digit content are treated as part of concept string."""# The regex will match "native.Text[abc]" as concept="native.Text[abc]", multiplicity=None# This will then fail during concept validation with ConceptCodeError- with pytest.raises(InputRequirementsFactoryError) as exc_info:- InputRequirementsFactory.make_from_string(domain="native", requirement_str="native.Text[abc]")+ with pytest.raises(InputStuffSpecsFactoryError) as exc_info:+ InputStuffSpecsFactory.make_from_string(domain="native", stuff_spec_str="native.Text[abc]")assert exc_info.value.__cause__ is not Noneassert isinstance(exc_info.value.__cause__, ConceptStringError)def test_multiplicity_zero_in_brackets(self, load_empty_library: Callable[[], None]):load_empty_library()"""Test parsing a concept string with 0 in brackets."""- result = InputRequirementsFactory.make_from_string(domain="native", requirement_str="native.Text[0]")+ result = InputStuffSpecsFactory.make_from_string(domain="native", stuff_spec_str="native.Text[0]")- assert isinstance(result, InputRequirement)+ assert isinstance(result, StuffSpec)assert result.concept.concept_string == "native.Text"assert result.multiplicity == 0def test_return_type(self, load_empty_library: Callable[[], None]):load_empty_library()- """Test that the method returns an InputRequirement instance."""- result = InputRequirementsFactory.make_from_string(domain="native", requirement_str="native.Text")- assert isinstance(result, InputRequirement)+ """Test that the method returns an StuffSpec instance."""+ result = InputStuffSpecsFactory.make_from_string(domain="native", stuff_spec_str="native.Text")+ assert isinstance(result, StuffSpec)def test_concept_attribute_access(self, load_empty_library: Callable[[], None]):load_empty_library()- """Test that the returned InputRequirement has proper concept attributes."""- result = InputRequirementsFactory.make_from_string(domain="native", requirement_str="native.Text[5]")+ """Test that the returned StuffSpec has proper concept attributes."""+ result = InputStuffSpecsFactory.make_from_string(domain="native", stuff_spec_str="native.Text[5]")assert hasattr(result, "concept")assert hasattr(result, "multiplicity")@@ -161,7 +161,7 @@ class TestMakeInputRequirementsFromString:def test_edge_case_very_long_number(self, load_empty_library: Callable[[], None]):load_empty_library()"""Test parsing with a very long number in brackets."""- result = InputRequirementsFactory.make_from_string(domain="native", requirement_str="native.Text[999999]")+ result = InputStuffSpecsFactory.make_from_string(domain="native", stuff_spec_str="native.Text[999999]")assert result.multiplicity == 999999assert result.concept.concept_string == "native.Text"@@ -170,14 +170,14 @@ class TestMakeInputRequirementsFromString:load_empty_library()"""Test that whitespace is not automatically trimmed."""# Whitespace should cause domain validation to fail- with pytest.raises(InputRequirementsFactoryError) as exc_info:- InputRequirementsFactory.make_from_string(domain="native", requirement_str=" native.Text")+ with pytest.raises(InputStuffSpecsFactoryError) as exc_info:+ InputStuffSpecsFactory.make_from_string(domain="native", stuff_spec_str=" native.Text")assert exc_info.value.__cause__ is not Noneassert isinstance(exc_info.value.__cause__, ConceptStringError)# Trailing whitespace should cause concept code validation to fail- with pytest.raises(InputRequirementsFactoryError) as exc_info:- InputRequirementsFactory.make_from_string(domain="native", requirement_str="native.Text ")+ with pytest.raises(InputStuffSpecsFactoryError) as exc_info:+ InputStuffSpecsFactory.make_from_string(domain="native", stuff_spec_str="native.Text ")assert exc_info.value.__cause__ is not Noneassert isinstance(exc_info.value.__cause__, ConceptStringError)@@ -186,8 +186,8 @@ class TestMakeInputRequirementsFromString:"""Test that multiple brackets are treated as part of the concept name."""# "native.Text[5][10]" should match as concept="native.Text[5]", multiplicity=10# This will fail during concept code validation- with pytest.raises(InputRequirementsFactoryError) as exc_info:- InputRequirementsFactory.make_from_string(domain="native", requirement_str="native.Text[5][10]")+ with pytest.raises(InputStuffSpecsFactoryError) as exc_info:+ InputStuffSpecsFactory.make_from_string(domain="native", stuff_spec_str="native.Text[5][10]")assert exc_info.value.__cause__ is not Noneassert isinstance(exc_info.value.__cause__, ConceptStringError)@@ -195,19 +195,19 @@ class TestMakeInputRequirementsFromString:load_empty_library()"""Test that brackets at the start are part of the concept name."""# This will fail during domain validation- with pytest.raises(InputRequirementsFactoryError) as exc_info:- InputRequirementsFactory.make_from_string(domain="native", requirement_str="[5]native.Text")+ with pytest.raises(InputStuffSpecsFactoryError) as exc_info:+ InputStuffSpecsFactory.make_from_string(domain="native", stuff_spec_str="[5]native.Text")assert exc_info.value.__cause__ is not Noneassert isinstance(exc_info.value.__cause__, ConceptStringError)@pytest.mark.parametrize(- ("domain", "requirement_str", "expected_concept_string", "expected_multiplicity", "description"),+ ("domain", "stuff_spec_str", "expected_concept_string", "expected_multiplicity", "description"),CONCEPT_CODE_RESOLUTION_TEST_CASES,)def test_concept_code_resolution(self,domain: str,- requirement_str: str,+ stuff_spec_str: str,expected_concept_string: str,expected_multiplicity: int | bool | None,description: str,@@ -220,34 +220,34 @@ class TestMakeInputRequirementsFromString:2. concept_codes_from_same_domain helps resolve ambiguous concept codes"""load_empty_library()- result = InputRequirementsFactory.make_from_string(+ result = InputStuffSpecsFactory.make_from_string(domain=domain,- requirement_str=requirement_str,+ stuff_spec_str=stuff_spec_str,)- assert isinstance(result, InputRequirement)+ assert isinstance(result, StuffSpec)assert result.concept.concept_string == expected_concept_string, f"Failed: {description}"assert result.multiplicity == expected_multiplicity, f"Failed: {description}"@pytest.mark.parametrize(- ("domain", "requirement_str", "expected_concept_string", "expected_multiplicity"),+ ("domain", "stuff_spec_str", "expected_concept_string", "expected_multiplicity"),EXPLICIT_DOMAIN_IN_STRING_TEST_CASES,)def test_explicit_domain_in_string(self,domain: str,- requirement_str: str,+ stuff_spec_str: str,expected_concept_string: str,expected_multiplicity: int | bool | None,load_empty_library: Callable[[], None],):"""Test that explicitly specifying a domain in the requirement string works correctly."""load_empty_library()- result = InputRequirementsFactory.make_from_string(+ result = InputStuffSpecsFactory.make_from_string(domain=domain,- requirement_str=requirement_str,+ stuff_spec_str=stuff_spec_str,)- assert isinstance(result, InputRequirement)+ assert isinstance(result, StuffSpec)assert result.concept.concept_string == expected_concept_stringassert result.multiplicity == expected_multiplicitydiff --git a/tests/unit/pipelex/core/pipes/test_parse_concept_with_multiplicity.py b/tests/unit/pipelex/core/pipes/test_parse_concept_with_multiplicity.pyindex cbbeb49fa..4e7ec9462 100644--- a/tests/unit/pipelex/core/pipes/test_parse_concept_with_multiplicity.py+++ b/tests/unit/pipelex/core/pipes/test_parse_concept_with_multiplicity.py@@ -74,3 +74,19 @@ class TestParseConceptWithMultiplicity:result = parse_concept_with_multiplicity("_internal.Data[]")assert result.concept == "_internal.Data"assert result.multiplicity is True++ def test_invalid_zero_multiplicity(self):+ """Test that zero multiplicity is rejected since a pipe must produce at least one output."""+ with pytest.raises(ValueError, match="multiplicity must be at least 1"):+ parse_concept_with_multiplicity("Text[0]")++ with pytest.raises(ValueError, match="multiplicity must be at least 1"):+ parse_concept_with_multiplicity("domain.Concept[0]")++ def test_invalid_negative_multiplicity(self):+ """Test that negative multiplicity is rejected (fails regex pattern)."""+ with pytest.raises(ValueError, match="Invalid concept specification syntax"):+ parse_concept_with_multiplicity("Text[-1]")++ with pytest.raises(ValueError, match="Invalid concept specification syntax"):+ parse_concept_with_multiplicity("domain.Concept[-5]")