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.
More solid error handling for bundle validation, loading, static, code generation etc.
Louis Choquel533a22986f73
diff --git a/pipelex/core/concepts/concept_blueprint.py b/pipelex/core/concepts/concept_blueprint.pyindex eaec48747..2582da942 100644--- a/pipelex/core/concepts/concept_blueprint.py+++ b/pipelex/core/concepts/concept_blueprint.py@@ -114,6 +114,7 @@ class ConceptStructureBlueprint(BaseModel):class ConceptBlueprint(BaseModel):model_config = ConfigDict(extra="forbid")+ source: str | None = Nonedefinition: str# TODO (non-blockiing): define a type for Union[str, ConceptStructureBlueprint] (ConceptChoice to be consistent with LLMChoice)structure: str | dict[str, str | ConceptStructureBlueprint] | None = Nonediff --git a/pipelex/core/concepts/concept_factory.py b/pipelex/core/concepts/concept_factory.pyindex ef37afd99..c604fb995 100644--- a/pipelex/core/concepts/concept_factory.py+++ b/pipelex/core/concepts/concept_factory.py@@ -1,5 +1,3 @@-from typing import Any-from kajson.kajson_manager import KajsonManagerfrom pydantic import BaseModel@@ -13,7 +11,7 @@ from pipelex.core.concepts.concept_native import NativeConceptEnumData, NativeCofrom pipelex.core.concepts.structure_generator import StructureGeneratorfrom pipelex.core.domains.domain import SpecialDomainfrom pipelex.core.stuffs.stuff_content import TextContent-from pipelex.exceptions import ConceptCodeError, ConceptDefinitionError, ConceptRefineError, StructureClassError+from pipelex.exceptions import ConceptCodeError, ConceptDefinitionError, ConceptRefineError, ConceptStructureGeneratorError, StructureClassErrorclass DomainAndConceptCode(BaseModel):@@ -138,7 +136,9 @@ class ConceptFactory:ConceptBlueprint.validate_concept_code(concept_code=concept_code)except ConceptCodeError as exc:msg = f"Could not validate concept code '{concept_code}' in domain '{domain}': {exc}"- raise ConceptDefinitionError(msg) from exc+ raise ConceptDefinitionError(+ message=msg, domain_code=domain, concept_code=concept_code, description=blueprint.definition, source=blueprint.source+ ) from excstructure_class_name: strcurrent_refine: str | None = None@@ -155,43 +155,53 @@ class ConceptFactory:structure_class_name = blueprint.structureelse:# Structure is defined as a ConceptStructureBlueprint - run the structure generator and put it in the class registry- try:- # Normalize the structure blueprint to ensure all values are ConceptStructureBlueprint objects- normalized_structure = cls.normalize_structure_blueprint(blueprint.structure)+ # Normalize the structure blueprint to ensure all values are ConceptStructureBlueprint objects+ normalized_structure = cls.normalize_structure_blueprint(blueprint.structure)- python_code = StructureGenerator().generate_from_structure_blueprint(+ try:+ _, the_generated_class = StructureGenerator().generate_from_structure_blueprint(class_name=concept_code,structure_blueprint=normalized_structure,)-- # Execute the generated Python code to register the class- exec_globals: dict[str, Any] = {}- exec(python_code, exec_globals)-- # Register the generated class- KajsonManager.get_class_registry().register_class(exec_globals[concept_code])-- # The structure_class_name of the concept is the concept_code- structure_class_name = concept_code-- except Exception as exc:- msg = f"Error generating structure class for concept '{concept_code}' in domain '{domain}': {exc}"- raise ConceptDefinitionError(msg) from exc+ except ConceptStructureGeneratorError as exc:+ msg = f"Error generating python code for structure class of concept '{concept_code}' in domain '{domain}': {exc}"+ raise ConceptDefinitionError(+ msg,+ domain_code=domain,+ concept_code=concept_code,+ description=blueprint.definition,+ structure_class_python_code=exc.structure_class_python_code,+ source=blueprint.source,+ ) from exc++ # Execute the generated Python code to register the class+ # exec_globals: dict[str, Any] = {}+ # exec(python_code, exec_globals)++ # Register the generated class+ KajsonManager.get_class_registry().register_class(the_generated_class)++ # The structure_class_name of the concept is the concept_code+ structure_class_name = concept_code# Handle refines definitionelif blueprint.refines:- # If we have refines, validate that there is no structure related to the concept code in the class registry+ # If we have refines, validate that there is not already a structure related to this concept code in the class registryif Concept.is_valid_structure_class(structure_class_name=concept_code):msg = (f"Concept '{concept_code}' in domain '{domain}' has refines but also has a structure class registered. ""A concept cannot have both structure and refines.")- raise ConceptDefinitionError(msg)+ raise ConceptDefinitionError(+ msg, domain_code=domain, concept_code=concept_code, description=blueprint.definition, source=blueprint.source+ )try:current_refine = cls.make_refine(refine=blueprint.refines)except ConceptRefineError as exc:msg = f"Could not validate refine '{blueprint.refines}' for concept '{concept_code}' in domain '{domain}': {exc}"- raise ConceptDefinitionError(msg) from exc+ raise ConceptDefinitionError(+ msg, domain_code=domain, concept_code=concept_code, description=blueprint.definition, source=blueprint.source+ ) from excstructure_class_name = current_refine.split(".")[1] + "Content" if current_refine else TextContent.__name__# Handle neither structure nor refines - check the class registry# If there is a class, use it. structure_class_name is then the concept_codediff --git a/pipelex/core/concepts/structure_generator.py b/pipelex/core/concepts/structure_generator.pyindex b740d0f2e..f1ad25018 100644--- a/pipelex/core/concepts/structure_generator.py+++ b/pipelex/core/concepts/structure_generator.py@@ -1,20 +1,22 @@import astfrom datetime import datetimefrom enum import Enum-from typing import Any, Literal, Optional, cast+from typing import Any, Literal, Optionalfrom pydantic import Field-from pipelex import logfrom pipelex.core.concepts.concept_blueprint import ConceptStructureBlueprint, ConceptStructureBlueprintFieldTypefrom pipelex.core.stuffs.stuff_content import StructuredContent+from pipelex.exceptions import ConceptStructureGeneratorError, PipelexError+++class ConceptStructureValidationError(PipelexError):+ passclass StructureGenerator:"""Generate Pydantic BaseModel classes from concept structure blueprints."""- # TODO: The methods that return False for a failed validation should just raise (proper errors).-def __init__(self):self.imports = {"from typing import Optional, List, Dict, Any, Literal",@@ -24,13 +26,7 @@ class StructureGenerator:}self.enum_definitions: dict[str, dict[str, Any]] = {} # Store enum definitions- def _format_default_value(self, value: Any) -> str:- """Format default value for Python code, ensuring strings use double quotes."""- if isinstance(value, str):- return f'"{value}"'- return repr(value)-- def generate_from_structure_blueprint(self, class_name: str, structure_blueprint: dict[str, ConceptStructureBlueprint]) -> str:+ def generate_from_structure_blueprint(self, class_name: str, structure_blueprint: dict[str, ConceptStructureBlueprint]) -> tuple[str, type]:"""Generate Python module content from structure blueprint.Args:@@ -38,11 +34,14 @@ class StructureGenerator:structure_blueprint: Dictionary mapping field names to their ConceptStructureBlueprint definitionsReturns:- Generated Python module content+ Generated Python module content, the generated class++ Raises:+ ConceptStructureGeneratorError: If the generated code is not syntactically correct or does not inherit from the required base class"""# Generate the class- class_code = self._generate_class_from_blueprint(class_name, structure_blueprint)+ class_code = self._generate_class_source_code_from_blueprint(class_name, structure_blueprint)# Generate the complete moduleimports_section = "\n".join(sorted(self.imports))@@ -50,13 +49,46 @@ class StructureGenerator:generated_code = f"{imports_section}\n\n\n{class_code}\n"# Validate the generated code- if not self.validate_generated_code(generated_code, class_name):- msg = f"Generated code for class '{class_name}' failed validation"- raise ValueError(msg)+ try:+ the_class = self.validate_generated_code(+ python_code=generated_code, expected_class_name=class_name, required_base_class=StructuredContent+ )+ except (ConceptStructureValidationError, SyntaxError, ValueError, ImportError, Exception) as exc:+ msg = f"Error validating generated code: {exc}"+ raise ConceptStructureGeneratorError(msg, structure_class_python_code=generated_code) from exc++ return generated_code, the_class++ def validate_generated_code(self, python_code: str, expected_class_name: str, required_base_class: type) -> type:+ """Validate that the generated Python code is syntactically correct and executable.++ Args:+ python_code: The generated Python code to validate+ expected_class_name: The name of the class that should be created+ required_base_class: The base class that the generated class should inherit from++ """+ ast.parse(python_code)++ compile(python_code, "<generated>", "exec")++ return self._validate_execution(+ python_code=python_code,+ expected_class_name=expected_class_name,+ required_base_class=required_base_class,+ )++ ############################################################+ # Private methods+ ############################################################- return generated_code+ def _format_default_value(self, value: Any) -> str:+ """Format default value for Python code, ensuring strings use double quotes."""+ if isinstance(value, str):+ return f'"{value}"'+ return repr(value)- def _generate_class_from_blueprint(self, class_name: str, structure_blueprint: dict[str, ConceptStructureBlueprint]) -> str:+ def _generate_class_source_code_from_blueprint(self, class_name: str, structure_blueprint: dict[str, ConceptStructureBlueprint]) -> str:"""Generate a class definition from ConceptStructureBlueprint.Args:@@ -302,142 +334,42 @@ class StructureGenerator:# Unknown FieldType, assume it's a custom typereturn str(field_type)- def validate_generated_code(self, python_code: str, expected_class_name: str) -> bool:- """Validate that the generated Python code is syntactically correct and executable.-- Args:- python_code: The generated Python code to validate- expected_class_name: The name of the class that should be created-- Returns:- True if the code is valid, False otherwise-- """- # Step 1: Syntax validation- if not self._validate_syntax(python_code):- return False+ def _validate_execution(self, python_code: str, expected_class_name: str, required_base_class: type) -> type:+ """Validate that the code executes and creates the expected class."""+ # Import necessary modules for the execution context+ from typing import Any # noqa: PLC0415++ # Provide necessary imports in the execution context+ exec_globals = {+ "__builtins__": __builtins__,+ "datetime": datetime,+ "Enum": Enum,+ "Optional": Optional,+ "List": list,+ "Dict": dict,+ "Any": Any,+ "Literal": Literal,+ "Field": Field,+ "StructuredContent": StructuredContent,+ }+ exec_locals: dict[str, Any] = {}+ exec(python_code, exec_globals, exec_locals)- # Step 2: Compilation validation- if not self._validate_compilation(python_code):- return False+ # Verify the expected class was created+ if expected_class_name not in exec_locals:+ msg = f"Expected class '{expected_class_name}' not found in generated code"+ raise ConceptStructureValidationError(msg)- # Step 3: Execution and class creation validation- if not self._validate_execution(python_code, expected_class_name):- return False+ the_class = exec_locals[expected_class_name]- # Step 4: Class instantiation validation- return self._validate_instantiation(python_code, expected_class_name)+ # Verify it's actually a class+ if not isinstance(the_class, type):+ msg = f"'{expected_class_name}' is not a class"+ raise ConceptStructureValidationError(msg)- def _validate_syntax(self, python_code: str) -> bool:- """Validate that the code has valid Python syntax."""- try:- ast.parse(python_code)- return True- except SyntaxError as e:- log.error(f"Syntax error in generated code: {e}")- return False-- def _validate_compilation(self, python_code: str) -> bool:- """Validate that the code can be compiled."""- try:- compile(python_code, "<generated>", "exec")- return True- except Exception as e:- log.error(f"Compilation error in generated code: {e}")- return False+ # Verify it inherits from the required base class+ if not issubclass(the_class, required_base_class):+ msg = f"'{expected_class_name}' does not inherit from {required_base_class.__name__}"+ raise ConceptStructureValidationError(msg)- def _validate_execution(self, python_code: str, expected_class_name: str) -> bool:- """Validate that the code executes and creates the expected class."""- try:- # Import necessary modules for the execution context- from datetime import datetime # noqa: PLC0415- from enum import Enum # noqa: PLC0415- from typing import Any, Dict, List, Literal, Optional # noqa: PLC0415,F401-- from pydantic import Field # noqa: PLC0415-- from pipelex.core.stuffs.stuff_content import StructuredContent # noqa: PLC0415-- # Provide necessary imports in the execution context- exec_globals = {- "__builtins__": __builtins__,- "datetime": datetime,- "Enum": Enum,- "Optional": Optional,- "List": list,- "Dict": dict,- "Any": Any,- "Literal": Literal,- "Field": Field,- "StructuredContent": StructuredContent,- }- exec_locals: dict[str, Any] = {}- exec(python_code, exec_globals, exec_locals)-- # Verify the expected class was created- if expected_class_name not in exec_locals:- log.error(f"Expected class '{expected_class_name}' not found in generated code")- return False-- # Verify it's actually a class- if not isinstance(exec_locals[expected_class_name], type):- log.error(f"'{expected_class_name}' is not a class")- return False-- return True-- except ImportError as e:- log.error(f"Import error in generated code: {e}")- return False- except Exception as e:- log.error(f"Execution error in generated code: {e}")- return False-- def _validate_instantiation(self, python_code: str, expected_class_name: str) -> bool:- try:- exec_globals = {- "__builtins__": __builtins__,- "datetime": datetime,- "Enum": Enum,- "Optional": Optional,- "List": list,- "Dict": dict,- "Any": Any,- "Literal": Literal,- "Field": Field,- "StructuredContent": StructuredContent,- }- exec_locals: dict[str, Any] = {}- exec(python_code, exec_globals, exec_locals)-- generated_class = cast("type[Any]", exec_locals[expected_class_name])-- # Try to create an instance (this will catch Pydantic validation issues)- # For validation purposes, we'll try to create an instance with minimal valid data- instance: Any = None- try:- # First try with no arguments (works for classes with all optional fields)- instance = generated_class()- except Exception:- # If that fails, try with empty dict (some models accept this)- try:- instance = generated_class()- except Exception:- # If that fails too, the class structure is probably fine but requires specific data- # For validation purposes, we'll just check that it's a valid Pydantic model class- if not hasattr(generated_class, "model_fields"):- log.error("Generated class doesn't appear to be a Pydantic model")- return False- # Class structure is valid, just requires specific data to instantiate- return True-- # Verify it's a Pydantic model with the expected structure- if instance is not None and not hasattr(instance, "model_fields"):- log.error("Generated class doesn't appear to be a Pydantic model")- return False-- return True-- except Exception as e:- log.error(f"Instantiation error in generated code: {e}")- return False+ return the_classdiff --git a/pipelex/core/domains/domain_blueprint.py b/pipelex/core/domains/domain_blueprint.pyindex 844f3b380..7132fcbf2 100644--- a/pipelex/core/domains/domain_blueprint.py+++ b/pipelex/core/domains/domain_blueprint.py@@ -5,8 +5,9 @@ from pipelex.tools.misc.string_utils import is_snake_caseclass DomainBlueprint(BaseModel):+ source: str | None = Nonecode: str- definition: str | None = None+ definition: strsystem_prompt: str | None = Nonesystem_prompt_to_structure: str | None = Noneprompt_template_to_structure: str | None = Nonediff --git a/pipelex/core/domains/domain_factory.py b/pipelex/core/domains/domain_factory.pyindex bc9dfc7f6..3d1d6cb98 100644--- a/pipelex/core/domains/domain_factory.py+++ b/pipelex/core/domains/domain_factory.py@@ -20,4 +20,4 @@ class DomainFactory:except ValidationError as exc:formatted_error_msg = format_pydantic_validation_error(exc)msg = f"Could not make domain from blueprint: {formatted_error_msg}"- raise DomainDefinitionError(msg) from exc+ raise DomainDefinitionError(message=msg, domain_code=blueprint.code, description=blueprint.definition) from excdiff --git a/pipelex/exceptions.py b/pipelex/exceptions.pyindex c8dfbdb45..9f4e064be 100644--- a/pipelex/exceptions.py+++ b/pipelex/exceptions.py@@ -140,14 +140,36 @@ class LibraryParsingError(LibraryError):pass-# TODO: add details from all cases raising this errorclass DomainDefinitionError(PipelexError):- pass+ def __init__(self, message: str, domain_code: str, description: str, source: str | None = None):+ self.domain_code = domain_code+ self.description = description+ self.source = source+ super().__init__(message)-# TODO: add details from all cases raising this errorclass ConceptDefinitionError(PipelexError):- pass+ def __init__(+ self,+ message: str,+ domain_code: str,+ concept_code: str,+ description: str,+ structure_class_python_code: str | None = None,+ source: str | None = None,+ ):+ self.domain_code = domain_code+ self.concept_code = concept_code+ self.description = description+ self.structure_class_python_code = structure_class_python_code+ self.source = source+ super().__init__(message)+++class ConceptStructureGeneratorError(PipelexError):+ def __init__(self, message: str, structure_class_python_code: str | None = None):+ self.structure_class_python_code = structure_class_python_code+ super().__init__(message)# TODO: add details from all cases raising this error@@ -155,12 +177,12 @@ class PipeDefinitionError(PipelexError):def __init__(self,message: str,- domain: str | None = None,+ domain_code: str | None = None,pipe_code: str | None = None,description: str | None = None,source: str | None = None,):- self.domain = domain+ self.domain_code = domain_codeself.pipe_code = pipe_codeself.description = descriptionself.source = source@@ -168,11 +190,11 @@ class PipeDefinitionError(PipelexError):super().__init__(message)def pipe_details(self) -> str:- if not self.domain and not self.pipe_code and not self.description and not self.source:+ if not self.domain_code and not self.pipe_code and not self.description and not self.source:return "No pipe details provided"details = "Pipe details:"- if self.domain:- details += f" • domain='{self.domain}'"+ if self.domain_code:+ details += f" • domain='{self.domain_code}'"if self.pipe_code:details += f" • pipe='{self.pipe_code}'"if self.description:@@ -182,6 +204,34 @@ class PipeDefinitionError(PipelexError):return details+class DomainLoadingError(LibraryLoadingError):+ def __init__(self, message: str, domain_code: str, description: str, source: str | None = None):+ self.domain_code = domain_code+ self.description = description+ self.source = source+ super().__init__(message)+++class ConceptLoadingError(LibraryLoadingError):+ def __init__(+ self, message: str, concept_definition_error: ConceptDefinitionError, concept_code: str, description: str, source: str | None = None+ ):+ self.concept_definition_error = concept_definition_error+ self.concept_code = concept_code+ self.description = description+ self.source = source+ super().__init__(message)+++class PipeLoadingError(LibraryLoadingError):+ def __init__(self, message: str, pipe_definition_error: PipeDefinitionError, pipe_code: str, description: str, source: str | None = None):+ self.pipe_definition_error = pipe_definition_error+ self.pipe_code = pipe_code+ self.description = description+ self.source = source+ super().__init__(message)++class UnexpectedPipeDefinitionError(PipeDefinitionError):passdiff --git a/pipelex/libraries/library_manager.py b/pipelex/libraries/library_manager.pyindex 165894425..4c43a1706 100644--- a/pipelex/libraries/library_manager.py+++ b/pipelex/libraries/library_manager.py@@ -23,11 +23,14 @@ from pipelex.core.pipes.pipe_library import PipeLibraryfrom pipelex.exceptions import (ConceptDefinitionError,ConceptLibraryError,+ ConceptLoadingError,DomainDefinitionError,+ DomainLoadingError,LibraryError,LibraryLoadingError,PipeDefinitionError,PipeLibraryError,+ PipeLoadingError,)from pipelex.libraries.library_config import LibraryConfigfrom pipelex.libraries.library_manager_abstract import LibraryManagerAbstract@@ -151,7 +154,7 @@ class LibraryManager(LibraryManagerAbstract):domain = self._load_domain_from_blueprint(blueprint)except DomainDefinitionError as exc:msg = f"Could not load domain from PLX blueprint at '{blueprint.source}', domain code: '{blueprint.domain}': {exc}"- raise LibraryLoadingError(msg) from exc+ raise DomainLoadingError(message=msg, domain_code=exc.domain_code, description=exc.description, source=exc.source) from excself.domain_library.add_domain(domain=domain)# Create and load concepts@@ -159,7 +162,9 @@ class LibraryManager(LibraryManagerAbstract):concepts = self._load_concepts_from_blueprint(blueprint)except ConceptDefinitionError as exc:msg = f"Could not load concepts from PLX blueprint at '{blueprint.source}', domain code: '{blueprint.domain}': {exc}"- raise LibraryLoadingError(msg) from exc+ raise ConceptLoadingError(+ message=msg, concept_definition_error=exc, concept_code=exc.concept_code, description=exc.description, source=exc.source+ ) from excself.concept_library.add_concepts(concepts=concepts)# Create and load pipes@@ -167,7 +172,9 @@ class LibraryManager(LibraryManagerAbstract):pipes = self._load_pipes_from_blueprint(blueprint)except PipeDefinitionError as exc:msg = f"Could not load pipes from PLX blueprint at '{blueprint.source}', domain code: '{blueprint.domain}': {exc}"- raise LibraryLoadingError(msg) from exc+ raise PipeLoadingError(+ message=msg, pipe_definition_error=exc, pipe_code=exc.pipe_code or "", description=exc.description or "", source=exc.source+ ) from excself.pipe_library.add_pipes(pipes=pipes)return pipes@@ -190,8 +197,9 @@ class LibraryManager(LibraryManagerAbstract):def _load_domain_from_blueprint(self, blueprint: PipelexBundleBlueprint) -> Domain:return DomainFactory.make_from_blueprint(blueprint=DomainBlueprint(+ source=blueprint.source,code=blueprint.domain,- definition=blueprint.definition,+ definition=blueprint.definition or "",system_prompt=blueprint.system_prompt,system_prompt_to_structure=blueprint.system_prompt_to_structure,prompt_template_to_structure=blueprint.prompt_template_to_structure,diff --git a/pipelex/libraries/pipelines/builder/builder.plx b/pipelex/libraries/pipelines/builder/builder.plxindex b44fe7e10..44cb78e0f 100644--- a/pipelex/libraries/pipelines/builder/builder.plx+++ b/pipelex/libraries/pipelines/builder/builder.plx@@ -224,7 +224,7 @@ function_name = "compile_in_pipelex_bundle_spec"# inputs = { pipelex_bundle_spec = "PipelexBundleSpec", failed_concepts = "ConceptFailure", fixed_concepts = "ConceptSpec", fixed_pipes = "PipeSpec", failed_pipes = "PipeFailure" }# output = "PipelexBundleSpec"# steps = [-# { pipe = "validate_dry_run", result = "validation_result" },+# { pipe = "validate_bundle_spec", result = "validation_result" },# { pipe = "handle_validation_result", result = "pipelex_bundle_spec" }# ]@@ -272,12 +272,12 @@ function_name = "compile_in_pipelex_bundle_spec"# output = "ValidationResult"# function_name = "validate_loading"-# [pipe.validate_dry_run]+# [pipe.validate_bundle_spec]# type = "PipeFunc"# description = "Validate the dry running the bundle's pipes and report only failed pipes."# inputs = { pipelex_bundle_spec = "PipelexBundleSpec" }# output = "ValidationResult"-# function_name = "validate_dry_run"+# function_name = "validate_bundle_spec"# [pipe.continue]# type = "PipeCompose"diff --git a/pipelex/libraries/pipelines/builder/builder.py b/pipelex/libraries/pipelines/builder/builder.pyindex 4e95c2668..c4a36e75d 100644--- a/pipelex/libraries/pipelines/builder/builder.py+++ b/pipelex/libraries/pipelines/builder/builder.py@@ -7,8 +7,16 @@ from pipelex.core.concepts.concept_blueprint import ConceptBlueprintfrom pipelex.core.domains.domain_blueprint import DomainBlueprintfrom pipelex.core.memory.working_memory import WorkingMemoryfrom pipelex.core.stuffs.stuff_content import ListContent, StructuredContent-from pipelex.exceptions import LibraryLoadingError, PipelexError, StaticValidationError-from pipelex.hub import get_library_manager+from pipelex.exceptions import (+ ConceptDefinitionError,+ ConceptLoadingError,+ DomainLoadingError,+ PipeDefinitionError,+ PipelexError,+ PipeLoadingError,+ StaticValidationError,+)+from pipelex.hub import get_class_registry, get_library_managerfrom pipelex.libraries.pipelines.builder.concept.concept_spec import ConceptSpecfrom pipelex.libraries.pipelines.builder.pipe.pipe_batch_spec import PipeBatchSpecfrom pipelex.libraries.pipelines.builder.pipe.pipe_compose_spec import PipeComposeSpec@@ -22,7 +30,6 @@ from pipelex.libraries.pipelines.builder.pipe.pipe_sequence_spec import PipeSequfrom pipelex.libraries.pipelines.builder.pipe.pipe_signature import PipeSignaturefrom pipelex.pipe_works.pipe_dry import dry_run_pipesfrom pipelex.tools.typing.pydantic_utils import format_pydantic_validation_error-from pipelex.types import StrEnumclass DomainInformation(StructuredContent):@@ -59,36 +66,79 @@ PipeSpecUnion = Annotated[]-class PipeFailure(StructuredContent):- """Details of a single pipe failure during dry run."""+class DomainFailure(StructuredContent):+ """Details of a single domain failure during dry run."""++ domain_code: str = Field(description="The code of the domain that failed")+ error_message: str = Field(description="The error message for this domain")- pipe: PipeSpecUnion = Field(description="The failing pipe spec blueprint with pipe code")- error_message: str = Field(description="The error message for this pipe")++# class DomainSpecError(PipelexError):+# """Details of a single domain failure during dry run."""++# def __init__(self, message: str, domain_failure: DomainFailure):+# self.domain_failure = domain_failure+# super().__init__(message)class ConceptFailure(StructuredContent):"""Details of a single concept failure during dry run."""- concept: ConceptSpec = Field(description="The failing concept spec blueprint with concept code")+ concept_spec: ConceptSpec = Field(description="The failing concept spec with concept code")error_message: str = Field(description="The error message for this concept")+class ConceptSpecError(PipelexError):+ """Details of a single concept failure during dry run."""++ def __init__(self, message: str, concept_failure: ConceptFailure):+ self.concept_failure = concept_failure+ super().__init__(message)+++class PipeFailure(StructuredContent):+ """Details of a single pipe failure during dry run."""++ pipe_spec: PipeSpecUnion = Field(description="The failing pipe spec with pipe code")+ error_message: str = Field(description="The error message for this pipe")+++class PipeSpecError(PipelexError):+ """Details of a single pipe failure during dry run."""++ def __init__(self, message: str, pipe_failure: PipeFailure):+ self.pipe_failure = pipe_failure+ super().__init__(message)+++class ValidateDryRunError(Exception):+ """Raised when validating the dry run of a pipe."""++class PipelexBundleError(PipelexError):def __init__(self,message: str,- pipe_code: str | None = None,- pipe_failure: PipeFailure | None = None,- concept_code: str | None = None,- concept_failure: ConceptFailure | None = None,+ static_validation_error: StaticValidationError | None = None,+ domain_failures: list[DomainFailure] | None = None,+ pipe_failures: list[PipeFailure] | None = None,+ concept_failures: list[ConceptFailure] | None = None,+ concept_definition_errors: list[ConceptDefinitionError] | None = None,+ pipe_definition_errors: list[PipeDefinitionError] | None = None,):- self.pipe_code = pipe_code- self.pipe_failure = pipe_failure- self.concept_code = concept_code- self.concept_failure = concept_failure+ self.static_validation_error = static_validation_error+ self.domain_failures = domain_failures+ self.pipe_failures = pipe_failures+ self.concept_failures = concept_failures+ self.concept_definition_errors = concept_definition_errors+ self.pipe_definition_errors = pipe_definition_errorssuper().__init__(message)+class PipelexBundleUnexpectedError(PipelexError):+ """Raised when an unexpected error occurs during validation."""++class PipelexBundleSpec(StructuredContent):"""Complete spec of a Pipelex bundle TOML definition.@@ -150,9 +200,9 @@ class PipelexBundleSpec(StructuredContent):try:concept[concept_code] = concept_spec_or_name.to_blueprint()except ValidationError as exc:- msg = f"Failed to validate concept spec for concept code {concept_code}: {format_pydantic_validation_error(exc)}"- concept_failure = ConceptFailure(concept=concept_spec_or_name, error_message=msg)- raise PipelexBundleError(message=msg, concept_code=concept_code, concept_failure=concept_failure) from exc+ msg = f"Failed to create concept blueprint from spec for concept code {concept_code}: {format_pydantic_validation_error(exc)}"+ concept_failure = ConceptFailure(concept_spec=concept_spec_or_name, error_message=msg)+ raise ConceptSpecError(message=msg, concept_failure=concept_failure) from excelse:concept[concept_code] = ConceptBlueprint(definition=concept_code, structure=concept_spec_or_name)@@ -163,9 +213,9 @@ class PipelexBundleSpec(StructuredContent):try:pipe[pipe_code] = pipe_spec.to_blueprint()except ValidationError as exc:- msg = f"Failed to validate pipe spec for pipe code {pipe_code}: {format_pydantic_validation_error(exc)}"- pipe_failure = PipeFailure(pipe=pipe_spec, error_message=msg)- raise PipelexBundleError(message=msg, pipe_code=pipe_code, pipe_failure=pipe_failure) from exc+ msg = f"Failed to create pipe blueprint from spec for pipe code {pipe_code}: {format_pydantic_validation_error(exc)}"+ pipe_failure = PipeFailure(pipe_spec=pipe_spec, error_message=msg)+ raise PipeSpecError(message=msg, pipe_failure=pipe_failure) from excreturn PipelexBundleBlueprint(domain=self.domain,@@ -245,95 +295,81 @@ async def compile_in_pipelex_bundle_spec(working_memory: WorkingMemory) -> Pipel# FAILURE = "FAILURE"-class Status(StrEnum):- SUCCESS = "SUCCESS"- FAILURE = "FAILURE"---class ValidationFollowUp(StrEnum):- CONTINUE = "continue"- FIX_PIPES = "fix_pipes"- FIX_CONCEPTS = "fix_concepts"+# class Status(StrEnum):+# SUCCESS = "SUCCESS"+# FAILURE = "FAILURE"-class ValidateDryRunError(Exception):- """Raised when validating the dry run of a pipelex bundle blueprint."""+# class ValidationFollowUp(StrEnum):+# CONTINUE = "continue"+# FIX_PIPES = "fix_pipes"+# FIX_CONCEPTS = "fix_concepts"-class ValidationResult(StructuredContent):- status: Status- error_message: str | None = Field(default=None, description="The error message for the failure if applicable")- failed_pipes: ListContent[PipeFailure] | None = Field(default=None, description="The error details for the failure if applicable")- failed_concepts: ListContent[ConceptFailure] | None = Field(default=None, description="The error details for the failure if applicable")+# class ValidationResult(StructuredContent):+# status: Status+# error_message: str | None = Field(default=None, description="The error message for the failure if applicable")+# failed_pipes: ListContent[PipeSpecFailure] | None = Field(default=None, description="The error details for the failure if applicable")+# failed_concepts: ListContent[ConceptSpecFailure] | None = Field(default=None, description="The error details for the failure if applicable")-async def validate_loading(working_memory: WorkingMemory) -> ValidationResult:+async def validate_bundle_spec(working_memory: WorkingMemory):library_manager = get_library_manager()pipelex_bundle_spec = working_memory.get_stuff_as(name="pipelex_bundle_spec", content_type=PipelexBundleSpec)try:pipelex_bundle_blueprint = pipelex_bundle_spec.to_blueprint()- except PipelexBundleError as exc:- if exc.concept_failure:- failed_concepts = ListContent[ConceptFailure](items=[exc.concept_failure])- return ValidationResult(status=Status.FAILURE, error_message=exc.message, failed_concepts=failed_concepts)- elif exc.pipe_failure:- failed_pipes = ListContent[PipeFailure](items=[exc.pipe_failure])- return ValidationResult(status=Status.FAILURE, error_message=exc.message, failed_pipes=failed_pipes)- else:- return ValidationResult(status=Status.FAILURE, error_message=exc.message)- try:- library_manager.load_from_blueprint(blueprint=pipelex_bundle_blueprint)- except LibraryLoadingError as library_loading_exc:- return ValidationResult(status=Status.FAILURE, error_message=str(library_loading_exc))- except StaticValidationError as static_validation_exc:- return ValidationResult(status=Status.FAILURE, error_message=str(static_validation_exc))-- library_manager.remove_from_blueprint(blueprint=pipelex_bundle_blueprint)- return ValidationResult(status=Status.SUCCESS)---async def validate_dry_run(working_memory: WorkingMemory) -> ValidationResult:- pipelex_bundle_spec = working_memory.get_stuff_as(name="pipelex_bundle_spec", content_type=PipelexBundleSpec)- pipelex_bundle_blueprint = pipelex_bundle_spec.to_blueprint()+ except ConceptSpecError as concept_spec_error:+ concept_failures = [concept_spec_error.concept_failure]+ raise PipelexBundleError(message=concept_spec_error.message, concept_failures=concept_failures) from concept_spec_error+ except PipeSpecError as pipe_spec_error:+ pipe_failures = [pipe_spec_error.pipe_failure]+ raise PipelexBundleError(message=pipe_spec_error.message, pipe_failures=pipe_failures) from pipe_spec_error- library_manager = get_library_manager()+ try:+ pipes = library_manager.load_from_blueprint(blueprint=pipelex_bundle_blueprint)+ except StaticValidationError as static_validation_error:+ raise PipelexBundleError(message=static_validation_error.desc(), static_validation_error=static_validation_error) from static_validation_error+ except DomainLoadingError as domain_loading_error:+ domain_failures = [DomainFailure(domain_code=domain_loading_error.domain_code, error_message=str(domain_loading_error))]+ raise PipelexBundleError(message=domain_loading_error.message, domain_failures=domain_failures) from domain_loading_error+ except ConceptLoadingError as concept_loading_error:+ raise PipelexBundleError(+ message=concept_loading_error.message, concept_definition_errors=[concept_loading_error.concept_definition_error]+ ) from concept_loading_error+ except PipeLoadingError as pipe_loading_error:+ raise PipelexBundleError(+ message=pipe_loading_error.message, pipe_definition_errors=[pipe_loading_error.pipe_definition_error]+ ) from pipe_loading_error- pipes = library_manager.load_from_blueprint(blueprint=pipelex_bundle_blueprint)dry_run_result = await dry_run_pipes(pipes=pipes, raise_on_failure=False)library_manager.remove_from_blueprint(blueprint=pipelex_bundle_blueprint)- pipe_type_to_spec_class = {- "PipeFunc": PipeFuncSpec,- "PipeImgGen": PipeImgGenSpec,- "PipeCompose": PipeComposeSpec,- "PipeLLM": PipeLLMSpec,- "PipeOcr": PipeOcrSpec,- "PipeBatch": PipeBatchSpec,- "PipeCondition": PipeConditionSpec,- "PipeParallel": PipeParallelSpec,- "PipeSequence": PipeSequenceSpec,- }-- failed_pipes: list[PipeFailure] = []+ dry_run_pipe_failures: list[PipeFailure] = []for pipe_code, dry_run_output in dry_run_result.items():- if dry_run_output.status.is_failure and pipelex_bundle_spec.pipe and pipe_code in pipelex_bundle_spec.pipe:- pipe_spec = pipelex_bundle_spec.pipe[pipe_code]- spec_class = pipe_type_to_spec_class.get(pipe_spec.type)+ if dry_run_output.status.is_failure:+ if not pipelex_bundle_spec.pipe:+ msg = f"No pipes section found in bundle spec but we recorded a dry run failure for pipe '{pipe_code}'"+ raise PipelexBundleUnexpectedError(message="No pipes section found in bundle spec")+ if pipe_code not in pipelex_bundle_spec.pipe:+ msg = f"Pipe '{pipe_code}' not found in bundle spec but we recorded a dry run failure for it"+ raise PipelexBundleUnexpectedError(message=msg)++ failing_pipe_spec = pipelex_bundle_spec.pipe[pipe_code]+ pipe_spec_type_name = failing_pipe_spec.type+ pipe_spec_class_name = pipe_spec_type_name + "Spec"+ spec_class = get_class_registry().get_class(name=pipe_spec_class_name)if not spec_class:- msg = f"Unknown pipe type: {pipe_spec.type}"- raise ValidateDryRunError(msg)- pipe_spec = spec_class(**pipe_spec.model_dump(serialize_as_any=True))- failed_pipes.append(+ msg = f"Unknown pipe spec class: {pipe_spec_class_name}"+ raise PipelexBundleUnexpectedError(message=msg)+ pipe_spec = spec_class.model_validate(obj=failing_pipe_spec.model_dump(serialize_as_any=True))+ dry_run_pipe_failures.append(PipeFailure(- pipe=pipe_spec,+ pipe_spec=pipe_spec,error_message=dry_run_output.error_message or "",),)- if failed_pipes:- failed_pipes_list_content = ListContent[PipeFailure](items=failed_pipes)- return ValidationResult(status=Status.FAILURE, failed_pipes=failed_pipes_list_content)- else:- return ValidationResult(status=Status.SUCCESS)+ if dry_run_pipe_failures:+ raise PipelexBundleError(message="Pipes failed during dry run", pipe_failures=dry_run_pipe_failures)async def reconstruct_bundle_with_pipe_fixes(working_memory: WorkingMemory) -> PipelexBundleSpec:diff --git a/pipelex/libraries/pipelines/builder/pipe/pipe.plx b/pipelex/libraries/pipelines/builder/pipe/pipe.plxindex de717e35d..c9d7da7c8 100644--- a/pipelex/libraries/pipelines/builder/pipe/pipe.plx+++ b/pipelex/libraries/pipelines/builder/pipe/pipe.plx@@ -265,215 +265,215 @@ And here are the concepts you can use:# PIPE FIXERS — one per pipe type, all fixing specific pipe type issues# ────────────────────────────────────────────────────────────────────────────────-[pipe.fix_failing_pipe]-type = "PipeCondition"-description = "Route to specific pipe fixer based on the failing pipe type."-inputs = { pipelex_bundle_spec = "PipelexBundleSpec", failed_pipe = "PipeFailure" }-output = "Dynamic"-expression = "failed_pipe.pipe.type"--[pipe.fix_failing_pipe.pipe_map]-PipeLLM = "fix_failing_llm_pipe"-PipeImgGen = "fix_failing_imggen_pipe"-PipeOcr = "fix_failing_ocr_pipe"-PipeFunc = "fix_failing_func_pipe"-PipeCompose = "fix_failing_jinja2_pipe"-PipeSequence = "fix_failing_sequence_pipe"-PipeParallel = "fix_failing_parallel_pipe"-PipeCondition = "fix_failing_condition_pipe"-PipeBatch = "fix_failing_batch_pipe"--[pipe.fix_failing_llm_pipe]-type = "PipeLLM"-description = "Fix a failing PipeLLM spec based on its specific error."-inputs = { pipelex_bundle_spec = "PipelexBundleSpec", failed_pipe = "PipeFailure" }-output = "PipeLLMSpec"-llm = "llm_to_engineer"-prompt_template = """-Fix this failing PipeLLM spec.--Failing pipe:-@failed_pipe.pipe--Error message:-@failed_pipe.error_message--Please provide only the corrected PipeLLMSpec. Common LLM pipe issues to fix:-- Missing input variables in the pipe inputs that are referenced in prompt_template-- Incorrect variable names in prompt templates (use $ for inline, @ for blocks)-- Wrong concept types for inputs/outputs-- Missing llm configuration-- Invalid prompt template syntax-"""--[pipe.fix_failing_imggen_pipe]-type = "PipeLLM"-description = "Fix a failing PipeImgGen spec based on its specific error."-inputs = { pipelex_bundle_spec = "PipelexBundleSpec", failed_pipe = "PipeFailure" }-output = "PipeImgGenSpec"-llm = "llm_to_engineer"-prompt_template = """-Fix this failing PipeImgGen spec.--Failing pipe:-@failed_pipe.pipe--Error message:-@failed_pipe.error_message--Please provide only the corrected PipeImgGenSpec. Common ImgGen pipe issues to fix:-- Missing or incorrect prompt input (should be text concept)-- Invalid img_gen-- Missing required inputs for dynamic prompt generation-"""--[pipe.fix_failing_ocr_pipe]-type = "PipeLLM"-description = "Fix a failing PipeOcr spec based on its specific error."-inputs = { pipelex_bundle_spec = "PipelexBundleSpec", failed_pipe = "PipeFailure" }-output = "PipeOcrSpec"-llm = "llm_to_engineer"-prompt_template = """-Fix this failing PipeOcr spec.--VERY IMPORTANT: THE INPUT OF THE PIPEOCR must be either an image or a pdf or a concept which refines one of them.-Failing pipe:-@failed_pipe.pipe--Error message:-@failed_pipe.error_message--Please provide only the corrected PipeOcrSpec. Common OCR pipe issues to fix:-- Input must be of type Image or PDF-- Output should typically be Page (native concept)-- Missing or incorrect input concept types-"""--[pipe.fix_failing_func_pipe]-type = "PipeLLM"-description = "Fix a failing PipeFunc spec based on its specific error."-inputs = { pipelex_bundle_spec = "PipelexBundleSpec", failed_pipe = "PipeFailure" }-output = "PipeFuncSpec"-llm = "llm_to_engineer"-prompt_template = """-Fix this failing PipeFunc spec.--Failing pipe:-@failed_pipe.pipe--Error message:-@failed_pipe.error_message--Please provide only the corrected PipeFuncSpec. Common Func pipe issues to fix:-- Missing or incorrect function_name-- Wrong input/output concept types for the function-- Function not available in registry-"""--[pipe.fix_failing_jinja2_pipe]-type = "PipeLLM"-description = "Fix a failing PipeCompose spec based on its specific error."-inputs = { pipelex_bundle_spec = "PipelexBundleSpec", failed_pipe = "PipeFailure" }-output = "PipeComposeSpec"-llm = "llm_to_engineer"-prompt_template = """-Fix this failing PipeCompose spec.--Failing pipe:-@failed_pipe.pipe--Error message:-@failed_pipe.error_message--Please provide only the corrected PipeComposeSpec. Common Jinja2 pipe issues to fix:-- Invalid Jinja2 template syntax-- Missing input variables referenced in template-- Wrong concept types for inputs/outputs-"""--[pipe.fix_failing_sequence_pipe]-type = "PipeLLM"-description = "Fix a failing PipeSequence spec based on its specific error."-inputs = { pipelex_bundle_spec = "PipelexBundleSpec", failed_pipe = "PipeFailure" }-output = "PipeSequenceSpec"-llm = "llm_to_engineer"-prompt_template = """-Fix this failing PipeSequence spec.--Failing pipe:-@failed_pipe.pipe--Error message:-@failed_pipe.error_message--Please provide only the corrected PipeSequenceSpec. Common Sequence pipe issues to fix:-- Missing input variables needed by sub-pipes in steps-- Referenced pipe codes in steps that don't exist-- Circular dependencies in step order-- Wrong result names in steps-"""--[pipe.fix_failing_parallel_pipe]-type = "PipeLLM"-description = "Fix a failing PipeParallel spec based on its specific error."-inputs = { pipelex_bundle_spec = "PipelexBundleSpec", failed_pipe = "PipeFailure" }-output = "PipeParallelSpec"-llm = "llm_to_engineer"-prompt_template = """-Fix this failing PipeParallel spec.--Failing pipe:-@failed_pipe.pipe--Error message:-@failed_pipe.error_message--Please provide only the corrected PipeParallelSpec. Common Parallel pipe issues to fix:-- Missing input variables needed by parallel sub-pipes-- Referenced pipe codes that don't exist-- Incompatible output types from parallel branches-"""--[pipe.fix_failing_condition_pipe]-type = "PipeLLM"-description = "Fix a failing PipeCondition spec based on its specific error."-inputs = { pipelex_bundle_spec = "PipelexBundleSpec", failed_pipe = "PipeFailure" }-output = "PipeConditionSpec"-llm = "llm_to_engineer"-prompt_template = """-Fix this failing PipeCondition spec.--Failing pipe:-@failed_pipe.pipe--Error message:-@failed_pipe.error_message--Please provide only the corrected PipeConditionSpec. Common Condition pipe issues to fix:-- Invalid expression or expression_template syntax-- Referenced pipe codes in pipe_map that don't exist-- Missing input variables referenced in expression-- Incompatible output types from different condition branches-"""--[pipe.fix_failing_batch_pipe]-type = "PipeLLM"-description = "Fix a failing PipeBatch spec based on its specific error."-inputs = { pipelex_bundle_spec = "PipelexBundleSpec", failed_pipe = "PipeFailure" }-output = "PipeBatchSpec"-llm = "llm_to_engineer"-prompt_template = """-Fix this failing PipeBatch spec.--Failing pipe:-@failed_pipe.pipe--Error message:-@failed_pipe.error_message--Please provide only the corrected PipeBatchSpec. Common Batch pipe issues to fix:-- Missing branch_pipe_code or referenced pipe that doesn't exist-- Wrong input types for batch processing (should be ListContent)-- Missing batch parameters configuration-"""+# [pipe.fix_failing_pipe]+# type = "PipeCondition"+# description = "Route to specific pipe fixer based on the failing pipe type."+# inputs = { pipelex_bundle_spec = "PipelexBundleSpec", failed_pipe = "PipeFailure" }+# output = "Dynamic"+# expression = "failed_pipe.pipe.type"++# [pipe.fix_failing_pipe.pipe_map]+# PipeLLM = "fix_failing_llm_pipe"+# PipeImgGen = "fix_failing_imggen_pipe"+# PipeOcr = "fix_failing_ocr_pipe"+# PipeFunc = "fix_failing_func_pipe"+# PipeCompose = "fix_failing_jinja2_pipe"+# PipeSequence = "fix_failing_sequence_pipe"+# PipeParallel = "fix_failing_parallel_pipe"+# PipeCondition = "fix_failing_condition_pipe"+# PipeBatch = "fix_failing_batch_pipe"++# [pipe.fix_failing_llm_pipe]+# type = "PipeLLM"+# description = "Fix a failing PipeLLM spec based on its specific error."+# inputs = { pipelex_bundle_spec = "PipelexBundleSpec", failed_pipe = "PipeFailure" }+# output = "PipeLLMSpec"+# llm = "llm_to_engineer"+# prompt_template = """+# Fix this failing PipeLLM spec.++# Failing pipe:+# @failed_pipe.pipe++# Error message:+# @failed_pipe.error_message++# Please provide only the corrected PipeLLMSpec. Common LLM pipe issues to fix:+# - Missing input variables in the pipe inputs that are referenced in prompt_template+# - Incorrect variable names in prompt templates (use $ for inline, @ for blocks)+# - Wrong concept types for inputs/outputs+# - Missing llm configuration+# - Invalid prompt template syntax+# """++# [pipe.fix_failing_imggen_pipe]+# type = "PipeLLM"+# description = "Fix a failing PipeImgGen spec based on its specific error."+# inputs = { pipelex_bundle_spec = "PipelexBundleSpec", failed_pipe = "PipeFailure" }+# output = "PipeImgGenSpec"+# llm = "llm_to_engineer"+# prompt_template = """+# Fix this failing PipeImgGen spec.++# Failing pipe:+# @failed_pipe.pipe++# Error message:+# @failed_pipe.error_message++# Please provide only the corrected PipeImgGenSpec. Common ImgGen pipe issues to fix:+# - Missing or incorrect prompt input (should be text concept)+# - Invalid img_gen+# - Missing required inputs for dynamic prompt generation+# """++# [pipe.fix_failing_ocr_pipe]+# type = "PipeLLM"+# description = "Fix a failing PipeOcr spec based on its specific error."+# inputs = { pipelex_bundle_spec = "PipelexBundleSpec", failed_pipe = "PipeFailure" }+# output = "PipeOcrSpec"+# llm = "llm_to_engineer"+# prompt_template = """+# Fix this failing PipeOcr spec.++# VERY IMPORTANT: THE INPUT OF THE PIPEOCR must be either an image or a pdf or a concept which refines one of them.+# Failing pipe:+# @failed_pipe.pipe++# Error message:+# @failed_pipe.error_message++# Please provide only the corrected PipeOcrSpec. Common OCR pipe issues to fix:+# - Input must be of type Image or PDF+# - Output should typically be Page (native concept)+# - Missing or incorrect input concept types+# """++# [pipe.fix_failing_func_pipe]+# type = "PipeLLM"+# description = "Fix a failing PipeFunc spec based on its specific error."+# inputs = { pipelex_bundle_spec = "PipelexBundleSpec", failed_pipe = "PipeFailure" }+# output = "PipeFuncSpec"+# llm = "llm_to_engineer"+# prompt_template = """+# Fix this failing PipeFunc spec.++# Failing pipe:+# @failed_pipe.pipe++# Error message:+# @failed_pipe.error_message++# Please provide only the corrected PipeFuncSpec. Common Func pipe issues to fix:+# - Missing or incorrect function_name+# - Wrong input/output concept types for the function+# - Function not available in registry+# """++# [pipe.fix_failing_jinja2_pipe]+# type = "PipeLLM"+# description = "Fix a failing PipeCompose spec based on its specific error."+# inputs = { pipelex_bundle_spec = "PipelexBundleSpec", failed_pipe = "PipeFailure" }+# output = "PipeComposeSpec"+# llm = "llm_to_engineer"+# prompt_template = """+# Fix this failing PipeCompose spec.++# Failing pipe:+# @failed_pipe.pipe++# Error message:+# @failed_pipe.error_message++# Please provide only the corrected PipeComposeSpec. Common Jinja2 pipe issues to fix:+# - Invalid Jinja2 template syntax+# - Missing input variables referenced in template+# - Wrong concept types for inputs/outputs+# """++# [pipe.fix_failing_sequence_pipe]+# type = "PipeLLM"+# description = "Fix a failing PipeSequence spec based on its specific error."+# inputs = { pipelex_bundle_spec = "PipelexBundleSpec", failed_pipe = "PipeFailure" }+# output = "PipeSequenceSpec"+# llm = "llm_to_engineer"+# prompt_template = """+# Fix this failing PipeSequence spec.++# Failing pipe:+# @failed_pipe.pipe++# Error message:+# @failed_pipe.error_message++# Please provide only the corrected PipeSequenceSpec. Common Sequence pipe issues to fix:+# - Missing input variables needed by sub-pipes in steps+# - Referenced pipe codes in steps that don't exist+# - Circular dependencies in step order+# - Wrong result names in steps+# """++# [pipe.fix_failing_parallel_pipe]+# type = "PipeLLM"+# description = "Fix a failing PipeParallel spec based on its specific error."+# inputs = { pipelex_bundle_spec = "PipelexBundleSpec", failed_pipe = "PipeFailure" }+# output = "PipeParallelSpec"+# llm = "llm_to_engineer"+# prompt_template = """+# Fix this failing PipeParallel spec.++# Failing pipe:+# @failed_pipe.pipe++# Error message:+# @failed_pipe.error_message++# Please provide only the corrected PipeParallelSpec. Common Parallel pipe issues to fix:+# - Missing input variables needed by parallel sub-pipes+# - Referenced pipe codes that don't exist+# - Incompatible output types from parallel branches+# """++# [pipe.fix_failing_condition_pipe]+# type = "PipeLLM"+# description = "Fix a failing PipeCondition spec based on its specific error."+# inputs = { pipelex_bundle_spec = "PipelexBundleSpec", failed_pipe = "PipeFailure" }+# output = "PipeConditionSpec"+# llm = "llm_to_engineer"+# prompt_template = """+# Fix this failing PipeCondition spec.++# Failing pipe:+# @failed_pipe.pipe++# Error message:+# @failed_pipe.error_message++# Please provide only the corrected PipeConditionSpec. Common Condition pipe issues to fix:+# - Invalid expression or expression_template syntax+# - Referenced pipe codes in pipe_map that don't exist+# - Missing input variables referenced in expression+# - Incompatible output types from different condition branches+# """++# [pipe.fix_failing_batch_pipe]+# type = "PipeLLM"+# description = "Fix a failing PipeBatch spec based on its specific error."+# inputs = { pipelex_bundle_spec = "PipelexBundleSpec", failed_pipe = "PipeFailure" }+# output = "PipeBatchSpec"+# llm = "llm_to_engineer"+# prompt_template = """+# Fix this failing PipeBatch spec.++# Failing pipe:+# @failed_pipe.pipe++# Error message:+# @failed_pipe.error_message++# Please provide only the corrected PipeBatchSpec. Common Batch pipe issues to fix:+# - Missing branch_pipe_code or referenced pipe that doesn't exist+# - Wrong input types for batch processing (should be ListContent)+# - Missing batch parameters configuration+# """diff --git a/pipelex/pipe_works/pipe_dry.py b/pipelex/pipe_works/pipe_dry.pyindex 1c99944ba..45136ff76 100644--- a/pipelex/pipe_works/pipe_dry.py+++ b/pipelex/pipe_works/pipe_dry.py@@ -48,6 +48,7 @@ class DryRunOutput(BaseModel):async def dry_run_pipe(pipe: PipeAbstract, raise_on_failure: bool = False) -> DryRunOutput:"""Dry run a single pipe directly without parallelization."""allowed_to_fail_pipes = get_config().pipelex.dry_run_config.allowed_to_fail_pipes+ # TODO: fail and raise properlytry:needed_inputs_for_factory = _convert_to_working_memory_format(needed_inputs_spec=pipe.needed_inputs())@@ -90,6 +91,9 @@ async def dry_run_pipes(pipes: list[PipeAbstract], run_in_parallel: bool = True,Returns:Dict mapping pipe codes to their dry run status ("SUCCESS" or error message)+ Raises:+ DryRunError: If raise_on_failure is True and any pipe fails.+"""start_time = time.time()results: dict[str, DryRunOutput] = {}@@ -145,6 +149,7 @@ def _convert_to_working_memory_format(needed_inputs_spec: PipeInputSpec) -> listneeded_inputs_for_factory: list[TypedNamedInputRequirement] = []class_registry = get_class_registry()+ # TODO: fail and raise properlyfor named_input_requirement in needed_inputs_spec.named_input_requirements:try:# Get the concept and its structure classdiff --git a/tests/unit/pipelex/core/concepts/test_structured_output_generator.py b/tests/unit/pipelex/core/concepts/test_structured_output_generator.pyindex 1204c0f7a..6ff648034 100644--- a/tests/unit/pipelex/core/concepts/test_structured_output_generator.py+++ b/tests/unit/pipelex/core/concepts/test_structured_output_generator.py@@ -1,7 +1,10 @@+import pytest+from pipelex import pretty_printfrom pipelex.core.concepts.concept_blueprint import ConceptStructureBlueprint, ConceptStructureBlueprintFieldTypefrom pipelex.core.concepts.concept_factory import ConceptFactory-from pipelex.core.concepts.structure_generator import StructureGenerator+from pipelex.core.concepts.structure_generator import ConceptStructureValidationError, StructureGenerator+from pipelex.core.stuffs.stuff_content import StructuredContentclass TestStructureGenerator:@@ -15,7 +18,7 @@ class TestStructureGenerator:),}- result = StructureGenerator().generate_from_structure_blueprint("TestModel", structure_blueprint)+ result, _ = StructureGenerator().generate_from_structure_blueprint("TestModel", structure_blueprint)pretty_print(structure_blueprint, title="Source Blueprint")pretty_print(result, title="Generated Result")@@ -50,7 +53,7 @@ class TestStructureGenerator:),}- result = StructureGenerator().generate_from_structure_blueprint("ComplexModel", structure_blueprint)+ result, _ = StructureGenerator().generate_from_structure_blueprint("ComplexModel", structure_blueprint)pretty_print(structure_blueprint, title="Source Blueprint")pretty_print(result, title="Generated Result")@@ -79,7 +82,7 @@ class TestStructureGenerator:"size": ConceptStructureBlueprint(definition="Size of the product", choices=["XS", "S", "M", "L", "XL"], required=False),}- result = StructureGenerator().generate_from_structure_blueprint("Product", structure_blueprint)+ result, _ = StructureGenerator().generate_from_structure_blueprint("Product", structure_blueprint)pretty_print(structure_blueprint, title="Source Blueprint")pretty_print(result, title="Generated Result")@@ -104,7 +107,7 @@ class TestStructureGenerator:"""Test generation of structure with no fields."""structure_blueprint: dict[str, ConceptStructureBlueprint] = {}- result = StructureGenerator().generate_from_structure_blueprint("EmptyModel", structure_blueprint)+ result, _ = StructureGenerator().generate_from_structure_blueprint("EmptyModel", structure_blueprint)pretty_print(structure_blueprint, title="Source Blueprint")pretty_print(result, title="Generated Result")@@ -130,7 +133,7 @@ class TestStructureGenerator:"page_count": ConceptStructureBlueprint(definition="Number of pages", type=ConceptStructureBlueprintFieldType.INTEGER, required=False),}- result = StructureGenerator().generate_from_structure_blueprint("DocumentInfo", structure_blueprint)+ result, _ = StructureGenerator().generate_from_structure_blueprint("DocumentInfo", structure_blueprint)pretty_print(structure_blueprint, title="Source Blueprint")pretty_print(result, title="Generated Result")@@ -156,7 +159,7 @@ class TestStructureGenerator:"value": ConceptStructureBlueprint(definition="Test value", type=ConceptStructureBlueprintFieldType.TEXT, required=True),}- result = StructureGenerator().generate_from_structure_blueprint("ConvenienceTest", structure_blueprint)+ result, _ = StructureGenerator().generate_from_structure_blueprint("ConvenienceTest", structure_blueprint)pretty_print(structure_blueprint, title="Source Blueprint")pretty_print(result, title="Generated Result")@@ -190,7 +193,7 @@ class TestStructureGenerator:),}- result = StructureGenerator().generate_from_structure_blueprint("TypeMappingTest", structure_blueprint)+ result, _ = StructureGenerator().generate_from_structure_blueprint("TypeMappingTest", structure_blueprint)pretty_print(structure_blueprint, title="Source Blueprint")pretty_print(result, title="Generated Result")@@ -221,7 +224,7 @@ class TestStructureGenerator:"optional_field": ConceptStructureBlueprint(definition="Optional field", type=ConceptStructureBlueprintFieldType.TEXT, required=False),}- result = StructureGenerator().generate_from_structure_blueprint("RequiredFieldsModel", structure_blueprint)+ result, _ = StructureGenerator().generate_from_structure_blueprint("RequiredFieldsModel", structure_blueprint)pretty_print(structure_blueprint, title="Source Blueprint")pretty_print(result, title="Generated Result")@@ -255,7 +258,7 @@ class TestStructureGenerator:),}- result = StructureGenerator().generate_from_structure_blueprint("PersonWithDefaults", structure_blueprint)+ result, _ = StructureGenerator().generate_from_structure_blueprint("PersonWithDefaults", structure_blueprint)pretty_print(structure_blueprint, title="Source Blueprint")pretty_print(result, title="Generated Result")@@ -290,7 +293,7 @@ class TestStructureGenerator:),}- result = StructureGenerator().generate_from_structure_blueprint("ListTypesModel", structure_blueprint)+ result, _ = StructureGenerator().generate_from_structure_blueprint("ListTypesModel", structure_blueprint)pretty_print(structure_blueprint, title="Source Blueprint")pretty_print(result, title="Generated Result")@@ -337,7 +340,7 @@ class TestStructureGenerator:),}- result = StructureGenerator().generate_from_structure_blueprint("DictTypesModel", structure_blueprint)+ result, _ = StructureGenerator().generate_from_structure_blueprint("DictTypesModel", structure_blueprint)pretty_print(structure_blueprint, title="Source Blueprint")pretty_print(result, title="Generated Result")@@ -377,7 +380,7 @@ class TestStructureGenerator:),}- result = StructureGenerator().generate_from_structure_blueprint("ComplexItem", structure_blueprint)+ result, _ = StructureGenerator().generate_from_structure_blueprint("ComplexItem", structure_blueprint)pretty_print(structure_blueprint, title="Source Blueprint")pretty_print(result, title="Generated Result")@@ -414,7 +417,7 @@ class TestStructureGenerator:normalized_structure = ConceptFactory.normalize_structure_blueprint(mixed_structure_blueprint)- result = StructureGenerator().generate_from_structure_blueprint("PersonInfo", normalized_structure)+ result, _ = StructureGenerator().generate_from_structure_blueprint("PersonInfo", normalized_structure)pretty_print(mixed_structure_blueprint, title="Source Mixed Blueprint")pretty_print(normalized_structure, title="Normalized Blueprint")@@ -450,13 +453,15 @@ class TestStructureGenerator:}generator = StructureGenerator()- result = generator.generate_from_structure_blueprint("ValidTestModel", structure_blueprint)+ python_code, the_class = generator.generate_from_structure_blueprint("ValidTestModel", structure_blueprint)# The generation should succeed (validation happens internally)- assert "class ValidTestModel(StructuredContent):" in result+ assert "class ValidTestModel(StructuredContent):" in python_code+ assert isinstance(the_class, type)+ assert issubclass(the_class, StructuredContent)# Test validation directly- assert generator.validate_generated_code(result, "ValidTestModel") is True+ generator.validate_generated_code(python_code=python_code, expected_class_name="ValidTestModel", required_base_class=StructuredContent)def test_code_validation_syntax_error(self):"""Test that invalid syntax fails validation."""@@ -469,7 +474,8 @@ class InvalidModel(StructuredContent):name: str = Field(..., description="Name field" # Missing closing parenthesis"""- assert generator.validate_generated_code(invalid_code, "InvalidModel") is False+ with pytest.raises(SyntaxError):+ generator.validate_generated_code(python_code=invalid_code, expected_class_name="InvalidModel", required_base_class=StructuredContent)def test_code_validation_missing_class(self):"""Test that code without the expected class fails validation."""@@ -482,4 +488,5 @@ class WrongClassName(StructuredContent):name: str = Field(..., description="Name field")"""- assert generator.validate_generated_code(code_without_expected_class, "ExpectedClassName") is False+ with pytest.raises(ConceptStructureValidationError):+ generator.validate_generated_code(python_code=code_without_expected_class, expected_class_name="ExpectedClassName", required_base_class=StructuredContent)