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.
Command pipelex validate blueprint
Louis Choquel2e9a281d7a28
diff --git a/pipelex/cli/commands/validate_cmd.py b/pipelex/cli/commands/validate_cmd.pyindex 31b1a41ba..6b4a2a528 100644--- a/pipelex/cli/commands/validate_cmd.py+++ b/pipelex/cli/commands/validate_cmd.py@@ -6,6 +6,7 @@ from typing import Annotatedimport typerfrom pipelex import log+from pipelex.create.build_blueprint import validate_blueprint as do_validate_blueprintfrom pipelex.hub import get_pipeline_trackerfrom pipelex.pipe_works.pipe_dry import dry_run_all_pipes, dry_run_single_pipefrom pipelex.pipelex import Pipelex@@ -64,3 +65,28 @@ def dry_run_pipe_cmd(] = "./pipelex_libraries",) -> None:do_dry_run_pipe(pipe_code=pipe_code, relative_config_folder_path=relative_config_folder_path)+++@validate_app.command("blueprint")+def validate_blueprint_cmd(+ blueprint_path: Annotated[str, typer.Argument(help="Path to the blueprint TOML file to validate")],+ relative_config_folder_path: Annotated[+ str, typer.Option("--config-folder-path", "-c", help="Relative path to the config folder path")+ ] = "./pipelex_libraries",+) -> None:+ """Validate an already generated pipeline blueprint TOML file.++ This command loads the TOML file, validates it against the `PipelineBlueprint` model,+ loads the defined pipes into memory, and performs a dry-run validation of those pipes.+ """+ if not is_pipelex_libraries_folder(relative_config_folder_path):+ typer.echo(f"❌ No pipelex libraries folder found at '{relative_config_folder_path}'")+ typer.echo("To create a pipelex libraries folder, run: pipelex init-libraries")+ raise typer.Exit(1)++ # Initialize Pipelex (loads libraries and pipes)+ Pipelex.make(relative_config_folder_path=relative_config_folder_path, from_file=False)++ # Run validation+ asyncio.run(do_validate_blueprint(blueprint_path=blueprint_path))+ log.info("Blueprint validation completed successfully.")diff --git a/pipelex/create/build_blueprint.py b/pipelex/create/build_blueprint.pyindex 722e6df8b..183fbdeca 100644--- a/pipelex/create/build_blueprint.py+++ b/pipelex/create/build_blueprint.py@@ -18,6 +18,7 @@ from pipelex.pipe_works.pipe_dry import dry_run_pipe_codesfrom pipelex.pipeline.execute import execute_pipelinefrom pipelex.tools.misc.file_utils import save_text_to_pathfrom pipelex.tools.misc.json_utils import save_as_json_to_path+from pipelex.tools.misc.toml_utils import load_toml_from_pathfrom pipelex.tools.typing.pydantic_utils import format_pydantic_validation_error@@ -103,3 +104,44 @@ def _load_pipes_from_generated_blueprint(blueprint: PipelineBlueprint) -> None:pipe_blueprint=pipe_blueprint,)library_manager.pipe_library.add_new_pipe(pipe=pipe)+++async def validate_blueprint(blueprint_path: str) -> None:+ """Validate an already generated pipeline blueprint from a TOML file.++ Args:+ blueprint_path: Path to the blueprint TOML file to validate++ Raises:+ PipelexCLIError: If validation fails+ ValidationError: If the TOML structure doesn't match PipelineBlueprint+ """+ # Load the TOML file+ log.info(f"Loading blueprint from '{blueprint_path}'...")+ blueprint_dict = load_toml_from_path(path=blueprint_path)++ # Validate and create PipelineBlueprint model+ try:+ blueprint = PipelineBlueprint.model_validate(blueprint_dict)+ except ValidationError as exc:+ error_msg = format_pydantic_validation_error(exc=exc)+ raise PipelexCLIError(f"Invalid blueprint structure in '{blueprint_path}': {error_msg}") from exc++ log.info(f"Blueprint loaded successfully: domain='{blueprint.domain}'")++ # Load pipes from the blueprint+ try:+ _load_pipes_from_generated_blueprint(blueprint=blueprint)+ except PipeDefinitionError as exc:+ raise PipelexCLIError(f"Failed to load pipes from blueprint at '{blueprint_path}': {exc}") from exc++ # Get pipe codes and validate them+ generated_pipe_codes = list(blueprint.pipe.keys())+ if not generated_pipe_codes:+ raise PipelexCLIError("No pipe found in blueprint to validate")+ log.info(f"Loaded pipes: {generated_pipe_codes}")++ # Run validation+ log.info("Validating pipes...")+ await dry_run_pipe_codes(pipe_codes=generated_pipe_codes)+ log.info(f"✅ All pipes validated successfully: {generated_pipe_codes}")