Skip to content

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

Refactor/epic 3 improving builder pipeline (#301)

Louis Choquel694bf22fc795
diff --git a/.badges/tests.json b/.badges/tests.json
index 056566a85..5353808dd 100644
--- a/.badges/tests.json
+++ b/.badges/tests.json
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"label": "tests",
- "message": "1045",
+ "message": "1051",
"color": "blue",
"cacheSeconds": 300
}
\ No newline at end of file
diff --git a/.github/workflows/check-test-count-badge.yml b/.github/workflows/check-test-count-badge.yml
index ee6e243c1..bc4ddb7c7 100644
--- a/.github/workflows/check-test-count-badge.yml
+++ b/.github/workflows/check-test-count-badge.yml
@@ -2,10 +2,6 @@ name: Check test count matches badge
on:
pull_request:
- branches:
- - main
- - dev
- - "release/v[0-9]+.[0-9]+.[0-9]+"
jobs:
check:
diff --git a/.github/workflows/doc-check.yml b/.github/workflows/doc-check.yml
index 54a70d29a..362c2d833 100644
--- a/.github/workflows/doc-check.yml
+++ b/.github/workflows/doc-check.yml
@@ -2,10 +2,6 @@ name: Documentation Check
on:
pull_request:
- branches:
- - main
- - dev
- - "release/v[0-9]+.[0-9]+.[0-9]+"
paths:
- 'docs/**'
- 'mkdocs.yml'
diff --git a/.github/workflows/lint-check.yml b/.github/workflows/lint-check.yml
index 2eaed36dd..c4e82aa3d 100644
--- a/.github/workflows/lint-check.yml
+++ b/.github/workflows/lint-check.yml
@@ -2,10 +2,6 @@ name: Lint check
on:
pull_request:
- branches:
- - main
- - dev
- - "release/v[0-9]+.[0-9]+.[0-9]+"
jobs:
# --------------------------------------------------------------------------
diff --git a/.github/workflows/tests-check.yml b/.github/workflows/tests-check.yml
index 8e7229e63..532b4c43f 100644
--- a/.github/workflows/tests-check.yml
+++ b/.github/workflows/tests-check.yml
@@ -2,10 +2,6 @@ name: Tests check
on:
pull_request:
- branches:
- - main
- - dev
- - "release/v[0-9]+.[0-9]+.[0-9]+"
jobs:
matrix-test:
diff --git a/.pipelex/inference/routing_profiles.toml b/.pipelex/inference/routing_profiles.toml
index 7290382e0..85a11c6e1 100644
--- a/.pipelex/inference/routing_profiles.toml
+++ b/.pipelex/inference/routing_profiles.toml
@@ -48,6 +48,7 @@ default = "google"
[profiles.all_azure_openai]
description = "Use Azure OpenAI backend for all its supported models"
default = "azure_openai"
+
[profiles.custom_routing]
description = "Custom routing"
default = "pipelex_inference"
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 95b03a0cf..bea021d52 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,6 +26,7 @@
- Modified `any_env_var_is_placeholder()` to use new placeholder detection logic
- Updated test environment setup to use dynamic placeholder generation instead of hardcoded values
- Restructured test classes and methods in environment tests
+ - Lint and tests GHA should run on every PR
### Fixed
- Fixed logic error in `any_env_var_is_placeholder()` function - now correctly returns False when no placeholders are found
@@ -35,6 +36,8 @@
- Removed `get_rooted_path()` and `get_env_rooted_path()` utility functions
- Removed hardcoded placeholder dictionary in test setup
- Removed function `run_pipe_code` in pipe router because it was not relevant (used mostly in tests)
+ - Remove the use of `PipeCompose` in `PipeCondition`, to only use jinja2 with the `ContentGenerator`
+ - Remove the template libraries from the pipelex libraries.
## [v0.10.2] - 2025-09-18
diff --git a/Makefile b/Makefile
index ab8a0cd3a..734d12f8a 100644
--- a/Makefile
+++ b/Makefile
@@ -373,11 +373,11 @@ cm: cov-missing
format: env
$(call PRINT_TITLE,"Formatting with ruff")
- $(VENV_RUFF) format .
+ $(VENV_RUFF) format . --config pyproject.toml
lint: env
$(call PRINT_TITLE,"Linting with ruff")
- $(VENV_RUFF) check . --fix
+ $(VENV_RUFF) check . --fix --config pyproject.toml
pyright: env
$(call PRINT_TITLE,"Typechecking with pyright")
@@ -385,7 +385,7 @@ pyright: env
mypy: env
$(call PRINT_TITLE,"Typechecking with mypy")
- $(VENV_MYPY)
+ $(VENV_MYPY) --config-file pyproject.toml
pylint: env
$(call PRINT_TITLE,"Linting with pylint")
@@ -398,11 +398,11 @@ pylint: env
merge-check-ruff-format: env
$(call PRINT_TITLE,"Formatting with ruff")
- $(VENV_RUFF) format --check .
+ $(VENV_RUFF) format --check . --config pyproject.toml
merge-check-ruff-lint: env check-unused-imports
$(call PRINT_TITLE,"Linting with ruff without fixing files")
- $(VENV_RUFF) check .
+ $(VENV_RUFF) check . --config pyproject.toml
merge-check-pyright: env
$(call PRINT_TITLE,"Typechecking with pyright")
@@ -455,7 +455,7 @@ docs-deploy: env
### SHORTHANDS
##########################################################################################
-c: format lint pyright mypy pylint
+c: format lint pyright pylint mypy
@echo "> done: c = check"
cc: cleanderived c
diff --git a/docs/pages/build-reliable-ai-workflows-with-pipelex/pipe-operators/PipeJinja2.md b/docs/pages/build-reliable-ai-workflows-with-pipelex/pipe-operators/PipeCompose.md
similarity index 100%
rename from docs/pages/build-reliable-ai-workflows-with-pipelex/pipe-operators/PipeJinja2.md
rename to docs/pages/build-reliable-ai-workflows-with-pipelex/pipe-operators/PipeCompose.md
diff --git a/docs/pages/configuration/config-technical/cogt-config.md b/docs/pages/configuration/config-technical/cogt-config.md
index ea0d9e368..8896096ab 100644
--- a/docs/pages/configuration/config-technical/cogt-config.md
+++ b/docs/pages/configuration/config-technical/cogt-config.md
@@ -31,6 +31,7 @@ Configuration for all Language Model interactions:
```toml
[cogt.llm_config]
default_max_images = 100 # Maximum number of images in prompts
+is_structure_prompt_enabled = false
# Job configuration
[cogt.llm_config.llm_job_config]
@@ -172,6 +173,7 @@ is_auto_setup_preset_ocr = true
[cogt.llm_config]
default_max_images = 100
+is_structure_prompt_enabled = false
[cogt.llm_config.llm_job_config]
is_streaming_enabled = false
diff --git a/docs/pages/configuration/config-technical/inference-backend-config.md b/docs/pages/configuration/config-technical/inference-backend-config.md
index 83eb572ea..8bb35043e 100644
--- a/docs/pages/configuration/config-technical/inference-backend-config.md
+++ b/docs/pages/configuration/config-technical/inference-backend-config.md
@@ -72,6 +72,16 @@ llm = { llm_handle = "claude-4-sonnet", temperature = 0.7 }
# Model automatically routed through Pipelex Inference
```
+### Model Availability Note
+
+While Pipelex Inference provides access to most AI models through a unified API, certain specialized models require their native backend to be enabled directly:
+
+- **FAL image generation models** (e.g., Flux models) - Enable the FAL backend
+- **OpenAI image generation** (`gpt-image-1`) - Enable the OpenAI backend (should also work via Azure OpenAI, but we haven't been able to test this - if you've successfully used it on Azure, please let us know on [Discord](https://go.pipelex.com/discord) so we can validate this configuration)
+- **Mistral OCR models** - Enable the Mistral backend
+
+These models are not proxied through Pipelex Inference and require direct configuration of their respective backends with appropriate API keys.
+
## Inference Backends
Backends represent AI service providers that can offer LLMs, OCR models, or image generation models. Each backend is configured with its endpoint and authentication details.
@@ -102,6 +112,8 @@ enabled = true
# No API key needed for internal/local processing
```
+Set `enabled` to `true` to activate a backend, or `false` to disable it. When a backend is enabled, you must set its corresponding API key as an environment variable.
+
### Model Specifications
Each backend has its own model specification file in `.pipelex/inference/backends/`:
diff --git a/docs/pages/quick-start/index.md b/docs/pages/quick-start/index.md
index cd2f05ac6..5a1ef7b01 100644
--- a/docs/pages/quick-start/index.md
+++ b/docs/pages/quick-start/index.md
@@ -32,19 +32,37 @@ If you already have API keys from LLM providers, you can use them directly:
```bash
# Add to your .env file
+# To directly use models on OpenAI, you will need to set the following variable
OPENAI_API_KEY=your-openai-key
+# To directly use models on Anthropic, you will need to set the following variable
ANTHROPIC_API_KEY=your-anthropic-key
+# To directly use models on Google, you will need to set the following variable
GOOGLE_API_KEY=your-google-key
-# Or for Azure OpenAI
+# To directly use models on Mistral, you will need to set the following variable
+MISTRAL_API_KEY=your-mistral-key
+# To directly use models on FAL, you will need to set the following variable
+FAL_API_KEY=your-fal-key
+# To directly use models on XAI, you will need to set the following variable
+XAI_API_KEY=your-xai-key
+
+# To use models via Ollama, you will need to set the following variables
+OLLAMA_API_KEY=your-ollama-key
+# To use models via BlackboxAI, you will need to set the following variables
+BLACKBOX_API_KEY=your-blackboxai-key
+# To use models via Azure OpenAI, you will need to set the following variables
AZURE_API_KEY=your-azure-key
AZURE_API_BASE=your-azure-endpoint
-# Or for AWS Bedrock
+AZURE_API_VERSION=your-azure-version
+# To use models via AWS Bedrock, you will need to set the following variables
AWS_ACCESS_KEY_ID=your-aws-key
AWS_SECRET_ACCESS_KEY=your-aws-secret
+AWS_REGION=your-aws-region
```
-For complete configuration details, see the [Inference Backend Configuration](../configuration/config-technical/inference-backend-config.md) documentation.
+Adding those env variables is not enough. You also need to configure the inference backend to choose where to route the AI calls.
+See the [Inference Backend Configuration](../configuration/config-technical/inference-backend-config.md#inference-backends) documentation.
+For example, if you want to use a gemini model via GOOGLE, enable the google backend in `.pipelex/inference/backends.toml` and set the API key in your env.
---
## Your first LLM call with Pipelex
diff --git a/pipelex/cli/commands/build_cmd.py b/pipelex/cli/commands/build_cmd.py
index 567c83224..ba13a3cce 100644
--- a/pipelex/cli/commands/build_cmd.py
+++ b/pipelex/cli/commands/build_cmd.py
@@ -8,6 +8,7 @@ from pipelex import pretty_print
from pipelex.hub import get_report_delegate
from pipelex.language.plx_factory import PlxFactory
from pipelex.libraries.pipelines.builder.builder import PipelexBundleSpec
+from pipelex.libraries.pipelines.builder.builder_loop import BuilderLoop
from pipelex.pipelex import Pipelex
from pipelex.pipeline.execute import execute_pipeline
from pipelex.tools.misc.file_utils import ensure_directory_for_file_path, save_text_to_path
@@ -24,8 +25,8 @@ pipelex build pipe "Given an RDFP PDF, build a compliance matrix"
"""
-@build_app.command("pipe")
-def build_pipe_cmd(
+@build_app.command("one-shot")
+def build_one_shot_cmd(
brief: Annotated[
str,
typer.Argument(help="Brief description of what the pipeline should do"),
@@ -45,29 +46,77 @@ def build_pipe_cmd(
typer.echo("")
async def run_pipeline():
- if not no_output:
- if not output_path:
- typer.echo(typer.style("\n⚠️ Cannot save a pipeline to an empty file name", fg=typer.colors.RED))
- raise typer.Exit(1)
-
- ensure_directory_for_file_path(file_path=output_path)
- else:
+ if no_output:
typer.echo(typer.style("\n⚠️ Pipeline will not be saved to file (--no-output specified)", fg=typer.colors.YELLOW))
+ elif not output_path:
+ typer.echo(typer.style("\n🛑 Cannot save a pipeline to an empty file name", fg=typer.colors.RED))
+ raise typer.Exit(1)
+ else:
+ ensure_directory_for_file_path(file_path=output_path)
pipe_output = await execute_pipeline(
pipe_code="pipe_builder",
input_memory={"brief": brief},
)
pretty_print(pipe_output, title="Pipe Output")
+
+ # Save to file unless explicitly disabled with --no-output
+ if no_output:
+ typer.echo(typer.style("\n⚠️ Pipeline not saved to file (--no-output specified)", fg=typer.colors.YELLOW))
+ return
+
pipelex_bundle_spec = pipe_output.working_memory.get_stuff_as(name="pipelex_bundle_spec", content_type=PipelexBundleSpec)
plx_content = PlxFactory.make_plx_content(blueprint=pipelex_bundle_spec.to_blueprint())
+ save_text_to_path(text=plx_content, path=output_path)
+ typer.echo(typer.style(f"\n✅ Pipeline saved to: {output_path}", fg=typer.colors.GREEN))
- # Save to file unless explicitly disabled with --no-output
- if not no_output:
- save_text_to_path(text=plx_content, path=output_path)
- typer.echo(typer.style(f"\n✅ Pipeline saved to: {output_path}", fg=typer.colors.GREEN))
+ start_time = time.time()
+ asyncio.run(run_pipeline())
+ end_time = time.time()
+ typer.echo(typer.style(f"\n✅ Pipeline built in {end_time - start_time:.2f} seconds", fg=typer.colors.GREEN))
+
+ get_report_delegate().generate_report()
+
+
+@build_app.command("pipe")
+def build_pipe_cmd(
+ brief: Annotated[
+ str,
+ typer.Argument(help="Brief description of what the pipeline should do"),
+ ],
+ output_path: Annotated[
+ str,
+ typer.Option("--output", "-o", help="Path to save the generated PLX file"),
+ ] = "./results/generated_pipeline.plx",
+ no_output: Annotated[
+ bool,
+ typer.Option("--no-output", help="Skip saving the pipeline to file"),
+ ] = False,
+) -> None:
+ Pipelex.make(relative_config_folder_path="../../../pipelex/libraries", from_file=True)
+ typer.echo("=" * 70)
+ typer.echo(typer.style("🔥 Starting pipe builder... 🚀", fg=typer.colors.GREEN))
+ typer.echo("")
+
+ async def run_pipeline():
+ if no_output:
+ typer.echo(typer.style("\n⚠️ Pipeline will not be saved to file (--no-output specified)", fg=typer.colors.YELLOW))
+ elif not output_path:
+ typer.echo(typer.style("\n🛑 Cannot save a pipeline to an empty file name", fg=typer.colors.RED))
+ raise typer.Exit(1)
else:
+ ensure_directory_for_file_path(file_path=output_path)
+
+ builder_loop = BuilderLoop()
+ # Save to file unless explicitly disabled with --no-output
+ if no_output:
typer.echo(typer.style("\n⚠️ Pipeline not saved to file (--no-output specified)", fg=typer.colors.YELLOW))
+ return
+
+ pipelex_bundle_spec = await builder_loop.build_and_fix(pipe_code="pipe_builder", input_memory={"brief": brief})
+ plx_content = PlxFactory.make_plx_content(blueprint=pipelex_bundle_spec.to_blueprint())
+ save_text_to_path(text=plx_content, path=output_path)
+ typer.echo(typer.style(f"\n✅ Pipeline saved to: {output_path}", fg=typer.colors.GREEN))
start_time = time.time()
asyncio.run(run_pipeline())
diff --git a/pipelex/cli/commands/common.py b/pipelex/cli/commands/common.py
index 103f0b42a..8b567cf65 100644
--- a/pipelex/cli/commands/common.py
+++ b/pipelex/cli/commands/common.py
@@ -5,7 +5,6 @@ from typing import Final
REQUIRED_PIPELEX_SUBDIRS: Final[list[str]] = [
"pipelines",
- "templates",
]
diff --git a/pipelex/cogt/config_cogt.py b/pipelex/cogt/config_cogt.py
index 478e108e3..adcaed1c1 100644
--- a/pipelex/cogt/config_cogt.py
+++ b/pipelex/cogt/config_cogt.py
@@ -21,12 +21,15 @@ class ImgGenConfig(ConfigModel):
class InstructorConfig(ConfigModel):
is_openai_structured_output_enabled: bool
+ is_dump_kwargs_enabled: bool
+ is_dump_response_enabled: bool
+ is_dump_error_enabled: bool
class LLMConfig(ConfigModel):
instructor_config: InstructorConfig
llm_job_config: LLMJobConfig
-
+ is_structure_prompt_enabled: bool
default_max_images: int
diff --git a/pipelex/cogt/content_generation/content_generator.py b/pipelex/cogt/content_generation/content_generator.py
index 0280a4ef8..575f3636e 100644
--- a/pipelex/cogt/content_generation/content_generator.py
+++ b/pipelex/cogt/content_generation/content_generator.py
@@ -257,9 +257,7 @@ class ContentGenerator(ContentGeneratorProtocol):
prompting_style=prompting_style,
template_category=template_category,
)
- jinja2_text = await jinja2_gen_text(jinja2_assignment=jinja2_assignment)
- log.dev(f"{self.__class__.__name__} jinja2: {jinja2_text}")
- return jinja2_text
+ return await jinja2_gen_text(jinja2_assignment=jinja2_assignment)
@override
async def make_ocr_extract_pages(
diff --git a/pipelex/cogt/content_generation/jinja2_generate.py b/pipelex/cogt/content_generation/jinja2_generate.py
index 73474136c..995209e75 100644
--- a/pipelex/cogt/content_generation/jinja2_generate.py
+++ b/pipelex/cogt/content_generation/jinja2_generate.py
@@ -5,8 +5,8 @@ from pipelex.tools.templating.jinja2_rendering import render_jinja2
from pipelex.tools.templating.template_preprocessor import preprocess_template
-# TODO: get rid of this intermediate call which seems useless, or explain why it stays
async def jinja2_gen_text(jinja2_assignment: Jinja2Assignment) -> str:
+ # Intermediate call to preprocess the template with our syntax patterns (@, $, @?, etc.)
if jinja2_assignment.jinja2:
jinja2_assignment.jinja2 = preprocess_template(template=jinja2_assignment.jinja2)
check_jinja2_parsing(jinja2_assignment.jinja2)
diff --git a/pipelex/cogt/content_generation/llm_generate.py b/pipelex/cogt/content_generation/llm_generate.py
index 424597d38..e0d858100 100644
--- a/pipelex/cogt/content_generation/llm_generate.py
+++ b/pipelex/cogt/content_generation/llm_generate.py
@@ -52,6 +52,13 @@ async def llm_gen_object_list(object_assignment: ObjectAssignment) -> list[BaseM
class ListSchema(BaseModel):
items: list[item_class] # type: ignore[valid-type] # pyright: ignore[reportInvalidTypeForm]
+ ListSchema.__name__ = f"ListOf{item_class_name}"
+
+ if item_class.__doc__:
+ ListSchema.__doc__ = f"List wrapper for {item_class_name}.\n\nItem description:\n{item_class.__doc__}"
+ else:
+ ListSchema.__doc__ = f"A list of {item_class_name}."
+
wrapped_list: ListSchema = await llm_worker.gen_object(
llm_job=llm_job,
schema=ListSchema,
diff --git a/pipelex/cogt/llm/llm_prompt_factory_abstract.py b/pipelex/cogt/llm/llm_prompt_factory_abstract.py
index 1a30544a7..319ed2657 100644
--- a/pipelex/cogt/llm/llm_prompt_factory_abstract.py
+++ b/pipelex/cogt/llm/llm_prompt_factory_abstract.py
@@ -6,14 +6,6 @@ from pydantic import BaseModel
from pipelex.cogt.llm.llm_prompt import LLMPrompt
-def make_empty_prompt() -> LLMPrompt:
- return LLMPrompt(
- system_text=None,
- user_text=None,
- user_images=[],
- )
-
-
class LLMPromptFactoryAbstract(ABC, BaseModel):
@abstractmethod
async def make_llm_prompt_from_args(
@@ -21,8 +13,3 @@ class LLMPromptFactoryAbstract(ABC, BaseModel):
**prompt_arguments: Any,
) -> LLMPrompt:
pass
-
- @property
- @abstractmethod
- def desc(self) -> str:
- pass
diff --git a/pipelex/cogt/llm/llm_prompt_spec.py b/pipelex/cogt/llm/llm_prompt_spec.py
index 32457def0..5b3c17e1d 100644
--- a/pipelex/cogt/llm/llm_prompt_spec.py
+++ b/pipelex/cogt/llm/llm_prompt_spec.py
@@ -173,7 +173,7 @@ class LLMPromptSpec(BaseModel):
jinja2_blueprint.prompting_style = prompting_style
log.verbose(f"Setting prompting style to {prompting_style}")
- context: dict[str, Any] = context_provider.generate_context()
+ context: dict[str, Any] = context_provider.generate_jinja2_context()
if extra_params:
context.update(**extra_params)
if jinja2_blueprint.extra_context:
diff --git a/pipelex/cogt/llm/llm_prompt_template.py b/pipelex/cogt/llm/llm_prompt_template.py
index 6be640f18..94a67c3eb 100644
--- a/pipelex/cogt/llm/llm_prompt_template.py
+++ b/pipelex/cogt/llm/llm_prompt_template.py
@@ -6,12 +6,19 @@ from pipelex import log
from pipelex.cogt.exceptions import LLMPromptFactoryError, LLMPromptTemplateInputsError
from pipelex.cogt.image.prompt_image import PromptImage
from pipelex.cogt.llm.llm_prompt import LLMPrompt
-from pipelex.cogt.llm.llm_prompt_factory_abstract import LLMPromptFactoryAbstract, make_empty_prompt
+from pipelex.cogt.llm.llm_prompt_factory_abstract import LLMPromptFactoryAbstract
from pipelex.cogt.llm.llm_prompt_template_inputs import LLMPromptTemplateInputs
from pipelex.config import get_config
from pipelex.hub import get_template
from pipelex.tools.misc.string_utils import is_none_or_has_text
-from pipelex.tools.templating.template_provider_abstract import TemplateProviderAbstract
+
+
+def make_empty_prompt() -> LLMPrompt:
+ return LLMPrompt(
+ system_text=None,
+ user_text=None,
+ user_images=[],
+ )
class LLMPromptTemplate(LLMPromptFactoryAbstract):
@@ -22,21 +29,10 @@ class LLMPromptTemplate(LLMPromptFactoryAbstract):
source_system_template_name: str | None = None
source_user_template_name: str | None = None
- @property
- @override
- def desc(self) -> str:
- return f"{LLMPromptTemplate.__name__} based on proto prompt: {self.proto_prompt} and base inputs: {self.base_template_inputs}"
-
@override
async def make_llm_prompt_from_args(
self,
**prompt_arguments: Any,
- ) -> LLMPrompt:
- return self.synchro_make_llm_prompt_from_args(**prompt_arguments)
-
- def synchro_make_llm_prompt_from_args(
- self,
- **prompt_arguments: Any,
) -> LLMPrompt:
arguments_dict = prompt_arguments.copy()
@@ -117,47 +113,6 @@ class LLMPromptTemplate(LLMPromptFactoryAbstract):
return llm_prompt
- # factories of LLMPromptTemplate (which is a factory of LLMPrompt)
- @classmethod
- def from_template_name(
- cls,
- template_provider: TemplateProviderAbstract,
- system_text: str | None = None,
- user_text: str | None = None,
- user_images: list[PromptImage] | None = None,
- system_template_name: str | None = None,
- user_template_name: str | None = None,
- ) -> "LLMPromptTemplate":
- proto_prompt: LLMPrompt = LLMPrompt(
- system_text=system_text,
- user_text=user_text,
- user_images=user_images or [],
- )
- if user_template_name:
- proto_prompt.user_text = template_provider.get_template(user_template_name)
- if system_template_name:
- proto_prompt.system_text = template_provider.get_template(system_template_name)
- return cls(
- proto_prompt=proto_prompt,
- source_system_template_name=system_template_name,
- source_user_template_name=user_template_name,
- )
-
- # factories of LLMPromptTemplate (which is a factory of LLMPrompt)
- @classmethod
- def from_template_contents(
- cls,
- system_text: str | None = None,
- user_text: str | None = None,
- user_images: list[PromptImage] | None = None,
- ) -> "LLMPromptTemplate":
- proto_prompt = LLMPrompt(
- user_text=user_text,
- system_text=system_text,
- user_images=user_images or [],
- )
- return cls(proto_prompt=proto_prompt)
-
@classmethod
def for_structure_from_preliminary_text(cls) -> "LLMPromptTemplate":
generic_template_names = get_config().pipelex.generic_template_names
diff --git a/pipelex/cogt/model_routing/routing_profile_library.py b/pipelex/cogt/model_routing/routing_profile_library.py
index 949e8a60c..1fb265580 100644
--- a/pipelex/cogt/model_routing/routing_profile_library.py
+++ b/pipelex/cogt/model_routing/routing_profile_library.py
@@ -9,7 +9,7 @@ from pipelex.cogt.model_routing.routing_profile_factory import (
RoutingProfileLibraryBlueprint,
)
from pipelex.config import get_config
-from pipelex.tools.misc.toml_utils import TOMLValidationError, load_toml_from_path
+from pipelex.tools.misc.toml_utils import load_toml_from_path
from pipelex.types import Self
RoutingProfileLibraryRoot = dict[str, RoutingProfile]
@@ -47,9 +47,6 @@ class RoutingProfileLibrary(RootModel[RoutingProfileLibraryRoot]):
except FileNotFoundError as not_found_exc:
msg = f"Failed to load routing profile library from file '{routing_profile_library_path}': {not_found_exc}"
raise RoutingProfileLibraryNotFoundError(msg) from not_found_exc
- except TOMLValidationError as toml_validation_exc:
- msg = f"Failed to load routing profile library from file '{routing_profile_library_path}': {toml_validation_exc}"
- raise RoutingProfileLibraryError(msg) from toml_validation_exc
try:
catalog_blueprint = RoutingProfileLibraryBlueprint.model_validate(catalog_dict)
diff --git a/pipelex/cogt/models/model_manager.py b/pipelex/cogt/models/model_manager.py
index a314ac2ff..37f5dbaa2 100644
--- a/pipelex/cogt/models/model_manager.py
+++ b/pipelex/cogt/models/model_manager.py
@@ -13,9 +13,8 @@ from pipelex.cogt.model_routing.routing_profile_library import RoutingProfileLib
from pipelex.cogt.models.model_deck import ModelDeck, ModelDeckBlueprint
from pipelex.cogt.models.model_manager_abstract import ModelManagerAbstract
from pipelex.config import get_config
-from pipelex.exceptions import LibraryError
from pipelex.tools.misc.json_utils import deep_update
-from pipelex.tools.misc.toml_utils import TOMLValidationError, load_toml_from_path, validate_toml_file
+from pipelex.tools.misc.toml_utils import load_toml_from_path
class ModelManager(ModelManagerAbstract):
@@ -43,21 +42,6 @@ class ModelManager(ModelManagerAbstract):
deck_blueprint = self.load_deck_blueprint()
self.model_deck = self.build_deck(model_deck_blueprint=deck_blueprint)
- @classmethod
- def _validate_toml_files(cls) -> None:
- log.debug("LibraryManager deck TOML file formatting")
-
- # Validation of LLM deck paths
- deck_paths = get_config().cogt.inference_config.get_model_deck_paths()
- for deck_path in deck_paths:
- if os.path.exists(deck_path):
- try:
- validate_toml_file(deck_path)
- except TOMLValidationError as exc:
- msg = f"TOML validation failed for LLM deck file '{deck_path}': {exc}"
- log.error(msg)
- raise LibraryError(msg) from exc
-
@classmethod
def load_deck_blueprint(cls) -> ModelDeckBlueprint:
deck_paths = get_config().cogt.inference_config.get_model_deck_paths()
diff --git a/pipelex/core/concepts/concept.py b/pipelex/core/concepts/concept.py
index e8630ed25..b7dcc7357 100644
--- a/pipelex/core/concepts/concept.py
+++ b/pipelex/core/concepts/concept.py
@@ -80,7 +80,7 @@ class Concept(BaseModel):
except TypeError:
pass
- # Check if concept_1 has a field that is of type concept_2_class
+ # Check if concept_1 has compatible fields with concept_2
return ClassRegistryUtils.has_compatible_field(concept_1_class, concept_2_class)
return False
diff --git a/pipelex/core/concepts/concept_blueprint.py b/pipelex/core/concepts/concept_blueprint.py
index eaec48747..649b38b71 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 = None
definition: str
# TODO (non-blockiing): define a type for Union[str, ConceptStructureBlueprint] (ConceptChoice to be consistent with LLMChoice)
structure: str | dict[str, str | ConceptStructureBlueprint] | None = None
@@ -128,7 +129,10 @@ class ConceptBlueprint(BaseModel):
@classmethod
def validate_concept_code(cls, concept_code: str) -> None:
if not is_pascal_case(concept_code):
- msg = f"Concept code '{concept_code}' must be PascalCase (letters and numbers only, starting with uppercase, without `.`)"
+ msg = (
+ f"ConceptBlueprint validate_concept_code: Concept code '{concept_code}' must be PascalCase "
+ f"(letters and numbers only, starting with uppercase, without `.`)"
+ )
raise ConceptCodeError(msg)
@classmethod
@@ -164,7 +168,10 @@ class ConceptBlueprint(BaseModel):
# Validate concept code
if not is_pascal_case(concept_code):
- msg = f"Concept code '{concept_code}' must be PascalCase (letters and numbers only, starting with uppercase, without `.`)"
+ msg = (
+ f"ConceptBlueprint validate_concept_string: Concept code '{concept_code}' must be PascalCase "
+ f"(letters and numbers only, starting with uppercase, without `.`)"
+ )
raise ConceptCodeError(msg)
# Validate that if the concept code is among the native concepts, the domain MUST be native.
diff --git a/pipelex/core/concepts/concept_factory.py b/pipelex/core/concepts/concept_factory.py
index ef37afd99..d57201c12 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 KajsonManager
from pydantic import BaseModel
@@ -13,7 +11,7 @@ from pipelex.core.concepts.concept_native import NativeConceptEnumData, NativeCo
from pipelex.core.concepts.structure_generator import StructureGenerator
from pipelex.core.domains.domain import SpecialDomain
from pipelex.core.stuffs.stuff_content import TextContent
-from pipelex.exceptions import ConceptCodeError, ConceptDefinitionError, ConceptRefineError, StructureClassError
+from pipelex.exceptions import ConceptCodeError, ConceptDefinitionError, ConceptRefineError, ConceptStructureGeneratorError, StructureClassError
class DomainAndConceptCode(BaseModel):
@@ -126,6 +124,26 @@ class ConceptFactory:
raise ConceptRefineError(msg)
return NativeConceptManager.get_native_concept_string(concept_string_or_code=refine)
+ @classmethod
+ def make_from_blueprint_or_description(
+ cls,
+ domain: str,
+ concept_code: str,
+ concept_blueprint_or_description: ConceptBlueprint | str,
+ concept_codes_from_the_same_domain: list[str] | None = None,
+ ) -> Concept:
+ blueprint: ConceptBlueprint
+ if isinstance(concept_blueprint_or_description, str):
+ blueprint = ConceptBlueprint(definition=concept_blueprint_or_description)
+ else:
+ blueprint = concept_blueprint_or_description
+ return cls.make_from_blueprint(
+ domain=domain,
+ concept_code=concept_code,
+ blueprint=blueprint,
+ concept_codes_from_the_same_domain=concept_codes_from_the_same_domain,
+ )
+
@classmethod
def make_from_blueprint(
cls,
@@ -138,7 +156,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 exc
structure_class_name: str
current_refine: str | None = None
@@ -155,43 +175,49 @@ class ConceptFactory:
structure_class_name = blueprint.structure
else:
# 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
+
+ # 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 definition
elif 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 registry
if 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 exc
structure_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_code
diff --git a/pipelex/core/concepts/concept_library.py b/pipelex/core/concepts/concept_library.py
index 10b016681..95684a3d6 100644
--- a/pipelex/core/concepts/concept_library.py
+++ b/pipelex/core/concepts/concept_library.py
@@ -48,18 +48,6 @@ class ConceptLibrary(RootModel[ConceptLibraryRoot], ConceptProviderAbstract):
def make_empty(cls) -> Self:
return cls(root={})
- @override
- def get_native_concept(self, native_concept: NativeConceptEnum) -> Concept:
- try:
- return self.root[f"{SpecialDomain.NATIVE}.{native_concept}"]
- except KeyError as key_error:
- msg = f"Native concept '{native_concept}' not found in the library"
- raise ConceptLibraryConceptNotFoundError(msg) from key_error
-
- def get_native_concepts(self) -> list[Concept]:
- """Create all native concepts from the hardcoded data"""
- return [self.get_native_concept(native_concept=native_concept) for native_concept in NativeConceptEnum.values_list()]
-
@override
def list_concepts(self) -> list[Concept]:
return list(self.root.values())
@@ -89,6 +77,9 @@ class ConceptLibrary(RootModel[ConceptLibraryRoot], ConceptProviderAbstract):
def is_compatible(self, tested_concept: Concept, wanted_concept: Concept, strict: bool = False) -> bool:
return Concept.are_concept_compatible(concept_1=tested_concept, concept_2=wanted_concept, strict=strict)
+ def get_optional_concept(self, concept_string: str) -> Concept | None:
+ return self.root.get(concept_string)
+
@override
def get_required_concept(self, concept_string: str) -> Concept:
"""`concept_string` can have the domain or not. If it doesn't have the domain, it is assumed to be native.
@@ -97,7 +88,23 @@ class ConceptLibrary(RootModel[ConceptLibraryRoot], ConceptProviderAbstract):
if Concept.is_implicit_concept(concept_string=concept_string):
return ConceptFactory.make_implicit_concept(concept_string=concept_string)
ConceptBlueprint.validate_concept_string(concept_string=concept_string)
- return self.root[concept_string]
+ the_concept = self.get_optional_concept(concept_string=concept_string)
+ if not the_concept:
+ msg = f"Concept '{concept_string}' not found in the library"
+ raise ConceptLibraryConceptNotFoundError(msg)
+ return the_concept
+
+ @override
+ def get_native_concept(self, native_concept: NativeConceptEnum) -> Concept:
+ the_native_concept = self.get_optional_concept(f"{SpecialDomain.NATIVE}.{native_concept}")
+ if not the_native_concept:
+ msg = f"Native concept '{native_concept}' not found in the library"
+ raise ConceptLibraryConceptNotFoundError(msg)
+ return the_native_concept
+
+ def get_native_concepts(self) -> list[Concept]:
+ """Create all native concepts from the hardcoded data"""
+ return [self.get_native_concept(native_concept=native_concept) for native_concept in NativeConceptEnum.values_list()]
@override
def get_class(self, concept_code: str) -> type[Any] | None:
diff --git a/pipelex/core/concepts/structure_generator.py b/pipelex/core/concepts/structure_generator.py
index b740d0f2e..f1ad25018 100644
--- a/pipelex/core/concepts/structure_generator.py
+++ b/pipelex/core/concepts/structure_generator.py
@@ -1,20 +1,22 @@
import ast
from datetime import datetime
from enum import Enum
-from typing import Any, Literal, Optional, cast
+from typing import Any, Literal, Optional
from pydantic import Field
-from pipelex import log
from pipelex.core.concepts.concept_blueprint import ConceptStructureBlueprint, ConceptStructureBlueprintFieldType
from pipelex.core.stuffs.stuff_content import StructuredContent
+from pipelex.exceptions import ConceptStructureGeneratorError, PipelexError
+
+
+class ConceptStructureValidationError(PipelexError):
+ pass
class 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 definitions
Returns:
- 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 module
imports_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 type
return 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_class
diff --git a/pipelex/core/domains/domain_blueprint.py b/pipelex/core/domains/domain_blueprint.py
index 844f3b380..3b8b4dbce 100644
--- a/pipelex/core/domains/domain_blueprint.py
+++ b/pipelex/core/domains/domain_blueprint.py
@@ -1,12 +1,14 @@
-from pydantic import BaseModel
+from pydantic import BaseModel, ConfigDict
from pipelex.core.domains.exceptions import DomainError
from pipelex.tools.misc.string_utils import is_snake_case
class DomainBlueprint(BaseModel):
+ model_config = ConfigDict(extra="forbid")
+ source: str | None = None
code: str
- definition: str | None = None
+ definition: str
system_prompt: str | None = None
system_prompt_to_structure: str | None = None
prompt_template_to_structure: str | None = None
diff --git a/pipelex/core/domains/domain_factory.py b/pipelex/core/domains/domain_factory.py
index 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 exc
diff --git a/pipelex/core/interpreter.py b/pipelex/core/interpreter.py
index 383ce55e0..65cd9321c 100644
--- a/pipelex/core/interpreter.py
+++ b/pipelex/core/interpreter.py
@@ -8,11 +8,7 @@ from pipelex.core.bundles.pipelex_bundle_blueprint import PipelexBundleBlueprint
from pipelex.core.exceptions import (
PipelexConfigurationError,
)
-from pipelex.tools.misc.toml_utils import (
- clean_trailing_whitespace,
- validate_toml_content,
- validate_toml_file,
-)
+from pipelex.tools.misc.file_utils import load_text_from_path
from pipelex.types import Self
@@ -48,31 +44,15 @@ class PipelexInterpreter(BaseModel):
raise PipelexConfigurationError(msg)
return self
- @model_validator(mode="after")
- def validate_file_path(self) -> Self:
- if self.file_path:
- validate_toml_file(path=str(self.file_path))
- if self.file_content:
- validate_toml_content(content=self.file_content, file_path=str(self.file_path))
- return self
-
- def _read_and_reformat(self) -> str:
+ def _get_content(self) -> str:
"""Load PLX content from file_path or use file_content directly."""
if self.file_path:
- with open(self.file_path, encoding="utf-8") as file:
- file_content = file.read()
-
- # Clean trailing whitespace and write back if needed
- cleaned_content = clean_trailing_whitespace(file_content)
- if file_content != cleaned_content:
- with open(self.file_path, "w", encoding="utf-8") as file:
- file.write(cleaned_content)
- return cleaned_content
- return file_content
- if self.file_content is None:
+ return load_text_from_path(path=str(self.file_path))
+ elif self.file_content:
+ return self.file_content
+ else:
msg = "file_content must be provided if file_path is not provided"
raise PipelexConfigurationError(msg)
- return self.file_content
@staticmethod
def is_pipelex_file(file_path: Path) -> bool:
@@ -120,6 +100,8 @@ class PipelexInterpreter(BaseModel):
def make_pipelex_bundle_blueprint(self) -> PipelexBundleBlueprint:
"""Make a PipelexBundleBlueprint from the file_path or file_content"""
- file_content = self._read_and_reformat()
- plx_data = self._parse_plx_content(file_content)
- return PipelexBundleBlueprint.model_validate(plx_data)
+ file_content = self._get_content()
+ blueprint_dict = self._parse_plx_content(file_content)
+ if self.file_path:
+ blueprint_dict.update(source=str(self.file_path))
+ return PipelexBundleBlueprint.model_validate(blueprint_dict)
diff --git a/pipelex/core/memory/working_memory.py b/pipelex/core/memory/working_memory.py
index 349a125cc..347ce733b 100644
--- a/pipelex/core/memory/working_memory.py
+++ b/pipelex/core/memory/working_memory.py
@@ -196,7 +196,7 @@ class WorkingMemory(BaseModel, ContextProviderAbstract):
################################################################################################
@override
- def generate_context(self) -> dict[str, Any]:
+ def generate_jinja2_context(self) -> dict[str, Any]:
# TODO: Add unit tests for this method
artefact_dict: StuffArtefactDict = {}
for name, stuff in self.root.items():
diff --git a/pipelex/core/pipes/pipe_abstract.py b/pipelex/core/pipes/pipe_abstract.py
index 68705a742..5e543a183 100644
--- a/pipelex/core/pipes/pipe_abstract.py
+++ b/pipelex/core/pipes/pipe_abstract.py
@@ -25,8 +25,8 @@ class PipeAbstract(ABC, BaseModel):
output: Concept
@field_validator("code", mode="before")
- @staticmethod
- def validate_pipe_code_syntax(code: str) -> str:
+ @classmethod
+ def validate_pipe_code_syntax(cls, code: str) -> str:
PipeBlueprint.validate_pipe_code_syntax(pipe_code=code)
return code
@@ -34,10 +34,6 @@ class PipeAbstract(ABC, BaseModel):
def validate_output(self):
"""Validate the output for the pipe."""
- @property
- def class_name(self) -> str:
- return self.__class__.__name__
-
def validate_with_libraries(self):
"""Validate the pipe with the libraries, after the static validation"""
diff --git a/pipelex/core/pipes/pipe_blueprint.py b/pipelex/core/pipes/pipe_blueprint.py
index fc3dbe731..2568ae22a 100644
--- a/pipelex/core/pipes/pipe_blueprint.py
+++ b/pipelex/core/pipes/pipe_blueprint.py
@@ -1,6 +1,6 @@
from typing import Any
-from pydantic import BaseModel, field_validator
+from pydantic import BaseModel, ConfigDict, field_validator
from pipelex.core.concepts.concept_blueprint import ConceptBlueprint
from pipelex.core.pipes.exceptions import PipeBlueprintError
@@ -37,6 +37,7 @@ class AllowedPipeTypes(StrEnum):
class PipeBlueprint(BaseModel):
+ model_config = ConfigDict(extra="forbid")
source: str | None = None
category: Any
type: Any # TODO: Find a better way to handle this.
diff --git a/pipelex/core/pipes/pipe_run_params.py b/pipelex/core/pipes/pipe_run_params.py
index 34c0ac93e..741ca076a 100644
--- a/pipelex/core/pipes/pipe_run_params.py
+++ b/pipelex/core/pipes/pipe_run_params.py
@@ -34,7 +34,7 @@ class OutputMultiplicityResolution(BaseModel):
resolved_multiplicity: PipeOutputMultiplicity | None = Field(description="The final multiplicity value to use after resolution")
- enable_multiple_outputs: bool = Field(description="Whether multiple outputs should be generated")
+ is_multiple_outputs_enabled: bool = Field(description="Whether multiple outputs should be generated")
specific_output_count: int | None = Field(default=None, description="Exact number of outputs to generate, if specified")
@@ -126,19 +126,21 @@ def output_multiplicity_to_apply(
log.debug("base_multiplicity is bool")
return OutputMultiplicityResolution(
resolved_multiplicity=base_multiplicity,
- enable_multiple_outputs=base_multiplicity,
+ is_multiple_outputs_enabled=base_multiplicity,
specific_output_count=None,
)
elif isinstance(base_multiplicity, int):
log.debug("base_multiplicity is int")
return OutputMultiplicityResolution(
resolved_multiplicity=base_multiplicity,
- enable_multiple_outputs=True,
+ is_multiple_outputs_enabled=True,
specific_output_count=base_multiplicity,
)
else:
log.debug("base_multiplicity is None")
- return OutputMultiplicityResolution(resolved_multiplicity=base_multiplicity, enable_multiple_outputs=False, specific_output_count=None)
+ return OutputMultiplicityResolution(
+ resolved_multiplicity=base_multiplicity, is_multiple_outputs_enabled=False, specific_output_count=None
+ )
# Case 2: Override is a boolean
elif isinstance(override_multiplicity, bool):
@@ -149,24 +151,24 @@ def output_multiplicity_to_apply(
if isinstance(base_multiplicity, bool):
log.debug("base_multiplicity is bool - disregarding base, using True")
- return OutputMultiplicityResolution(resolved_multiplicity=True, enable_multiple_outputs=True, specific_output_count=None)
+ return OutputMultiplicityResolution(resolved_multiplicity=True, is_multiple_outputs_enabled=True, specific_output_count=None)
else:
log.debug("base_multiplicity is int or None - preserving base value")
return OutputMultiplicityResolution(
resolved_multiplicity=base_multiplicity,
- enable_multiple_outputs=True,
+ is_multiple_outputs_enabled=True,
specific_output_count=base_multiplicity if isinstance(base_multiplicity, int) else None,
)
else:
log.debug("override_multiplicity is False - forcing single output")
- return OutputMultiplicityResolution(resolved_multiplicity=False, enable_multiple_outputs=False, specific_output_count=None)
+ return OutputMultiplicityResolution(resolved_multiplicity=False, is_multiple_outputs_enabled=False, specific_output_count=None)
else:
# Case 3: Override is an integer
log.debug("override_multiplicity is int - using override value")
return OutputMultiplicityResolution(
resolved_multiplicity=override_multiplicity,
- enable_multiple_outputs=True,
+ is_multiple_outputs_enabled=True,
specific_output_count=override_multiplicity,
)
diff --git a/pipelex/core/pipes/specific_pipe.py b/pipelex/core/pipes/specific_pipe.py
index fb749fef5..963c2ea56 100644
--- a/pipelex/core/pipes/specific_pipe.py
+++ b/pipelex/core/pipes/specific_pipe.py
@@ -6,6 +6,10 @@ class SpecificPipeCodesEnum(StrEnum):
# TODO: Implement the break pipe: It should enable to leave the current sequence.
# BREAK = "break"
+ @classmethod
+ def value_list(cls) -> list[str]:
+ return list(cls)
+
# TODO: Rethink this class. They are not pipes really.
class SpecificPipe:
diff --git a/pipelex/exceptions.py b/pipelex/exceptions.py
index 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 error
class 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 error
class 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_code
self.pipe_code = pipe_code
self.description = description
self.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):
pass
diff --git a/pipelex/libraries/library_config.py b/pipelex/libraries/library_config.py
index 65e176f9b..e91e624e3 100644
--- a/pipelex/libraries/library_config.py
+++ b/pipelex/libraries/library_config.py
@@ -2,7 +2,7 @@ from pathlib import Path
from typing import ClassVar
from pipelex.tools.config.config_model import ConfigModel
-from pipelex.tools.misc.file_utils import copy_file_from_package, copy_folder_from_package, find_files_in_dir
+from pipelex.tools.misc.file_utils import copy_file_from_package, copy_folder_from_package
PIPELEX_LIBRARIES_PATH = "libraries"
@@ -19,10 +19,6 @@ class LibraryConfig(ConfigModel):
def base_pipelines_dir_path(self) -> str:
return f"{self.config_dir_path}/pipelines/base_library"
- @property
- def templates_dir_path(self) -> str:
- return f"{self.config_dir_path}/templates"
-
@property
def test_pipelines_dir_path(self) -> str:
return "tests/test_pipelines"
@@ -31,9 +27,6 @@ class LibraryConfig(ConfigModel):
def failing_pipelines_file_paths(self) -> set[Path]:
return {Path("tests/test_pipelines/failing_pipelines.plx")}
- def get_templates_paths(self) -> list[str]:
- return [str(path) for path in find_files_in_dir(dir_path=self.templates_dir_path, pattern="*.toml", is_recursive=True)]
-
def export_libraries(self, overwrite: bool = False) -> None:
"""Duplicate pipelex libraries files in the client project, preserving directory structure."""
copy_file_from_package(
@@ -56,11 +49,3 @@ class LibraryConfig(ConfigModel):
target_path=f"{self.pipelines_dir_path}/__init__.py",
overwrite=overwrite,
)
-
- # templates
- copy_folder_from_package(
- package_name=self.package_name,
- folder_path_in_package=f"{PIPELEX_LIBRARIES_PATH}/templates",
- target_dir=self.templates_dir_path,
- overwrite=overwrite,
- )
diff --git a/pipelex/libraries/library_manager.py b/pipelex/libraries/library_manager.py
index 165894425..a065650eb 100644
--- a/pipelex/libraries/library_manager.py
+++ b/pipelex/libraries/library_manager.py
@@ -1,4 +1,3 @@
-import os
from pathlib import Path
from typing import ClassVar
@@ -9,7 +8,6 @@ from pipelex import log
from pipelex.config import get_config
from pipelex.core.bundles.pipelex_bundle_blueprint import PipelexBundleBlueprint
from pipelex.core.concepts.concept import Concept
-from pipelex.core.concepts.concept_blueprint import ConceptBlueprint
from pipelex.core.concepts.concept_factory import ConceptFactory
from pipelex.core.concepts.concept_library import ConceptLibrary
from pipelex.core.domains.domain import Domain
@@ -23,18 +21,20 @@ from pipelex.core.pipes.pipe_library import PipeLibrary
from pipelex.exceptions import (
ConceptDefinitionError,
ConceptLibraryError,
+ ConceptLoadingError,
DomainDefinitionError,
+ DomainLoadingError,
LibraryError,
LibraryLoadingError,
PipeDefinitionError,
PipeLibraryError,
+ PipeLoadingError,
)
from pipelex.libraries.library_config import LibraryConfig
from pipelex.libraries.library_manager_abstract import LibraryManagerAbstract
from pipelex.tools.class_registry_utils import ClassRegistryUtils
from pipelex.tools.func_registry_utils import FuncRegistryUtils
from pipelex.tools.misc.file_utils import find_files_in_dir
-from pipelex.tools.misc.toml_utils import TOMLValidationError, validate_toml_file
from pipelex.tools.runtime_manager import runtime_manager
from pipelex.tools.typing.pydantic_utils import format_pydantic_validation_error
from pipelex.types import StrEnum
@@ -82,21 +82,6 @@ class LibraryManager(LibraryManagerAbstract):
self.pipe_library.validate_with_libraries()
self.domain_library.validate_with_libraries()
- def _validate_toml_files(self):
- """Validate all TOML files used by the library manager for formatting issues."""
- log.debug("LibraryManager validating TOML file formatting")
-
- # Validation of template paths
- template_paths = self.library_config.get_templates_paths()
- for template_path in template_paths:
- if os.path.exists(template_path):
- try:
- validate_toml_file(template_path)
- except TOMLValidationError as exc:
- msg = f"PLX validation failed for template file '{template_path}': {exc}"
- log.error(msg)
- raise LibraryError(msg) from exc
-
@override
def setup(self) -> None:
self.concept_library.setup()
@@ -151,7 +136,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 exc
self.domain_library.add_domain(domain=domain)
# Create and load concepts
@@ -159,7 +144,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 exc
self.concept_library.add_concepts(concepts=concepts)
# Create and load pipes
@@ -167,7 +154,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 exc
self.pipe_library.add_pipes(pipes=pipes)
return pipes
@@ -190,8 +179,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,
@@ -203,17 +193,12 @@ class LibraryManager(LibraryManagerAbstract):
return []
concepts: list[Concept] = []
- for concept_code, concept_blueprint_or_str in blueprint.concept.items():
- concept_blueprint: ConceptBlueprint
- if isinstance(concept_blueprint_or_str, str):
- concept_blueprint = ConceptBlueprint(definition=concept_blueprint_or_str)
- else:
- concept_blueprint = concept_blueprint_or_str
- concept = ConceptFactory.make_from_blueprint(
+ for concept_code, concept_blueprint_or_description in blueprint.concept.items():
+ concept = ConceptFactory.make_from_blueprint_or_description(
domain=blueprint.domain,
concept_code=concept_code,
concept_codes_from_the_same_domain=list(blueprint.concept.keys()),
- blueprint=concept_blueprint,
+ concept_blueprint_or_description=concept_blueprint_or_description,
)
concepts.append(concept)
return concepts
diff --git a/pipelex/libraries/pipelines/builder/builder.plx b/pipelex/libraries/pipelines/builder/builder.plx
index 6ff6abb07..71f0ff833 100644
--- a/pipelex/libraries/pipelines/builder/builder.plx
+++ b/pipelex/libraries/pipelines/builder/builder.plx
@@ -3,10 +3,12 @@ definition = "Auto-generate a Pipelex bundle (concepts + pipes) from a short use
[concept]
UserBrief = "A short, natural-language description of what the user wants."
-PlanDraftText = "Natural-language pipeline plan text describing sequences, inputs, outputs."
+PlanDraft = "Natural-language pipeline plan text describing sequences, inputs, outputs."
+ConceptDrafts = "Textual draft of the concepts to create."
PipelexBundleSpec = "A Pipelex bundle spec."
-PipeFailure = "Details of a single pipe failure during dry run."
-DryRunResult = "A result of a dry run of a pipelex bundle spec."
+ValidationResult = "Status (success or failure) and details of the validation failure if applicable."
+# PipeFailure = "Details of a single pipe failure during dry run."
+# DryRunResult = "A result of a dry run of a pipelex bundle spec."
DomainInformation = "A domain information object."
# ────────────────────────────────────────────────────────────────────────────────
@@ -15,358 +17,203 @@ DomainInformation = "A domain information object."
[pipe]
[pipe.pipe_builder]
type = "PipeSequence"
-description = "This pipe is going to be the entry point for the builder. It will take a UserBrief and return a PipelexBundleSpec."
+definition = "This pipe is going to be the entry point for the builder. It will take a UserBrief and return a PipelexBundleSpec."
inputs = { brief = "UserBrief" }
output = "PipelexBundleSpec"
steps = [
- { pipe = "draft_planning_text", result = "plan_draft" },
- { pipe = "parallel_draft_to_specs" },
- { pipe = "materialize_concept_spec_drafts", result = "concept_spec_drafts" },
- { pipe = "materialize_pipe_signatures", result = "pipe_signatures" },
+ { pipe = "draft_the_plan", result = "plan_draft" },
+ { pipe = "draft_the_concepts", result = "concept_drafts" },
+ { pipe = "structure_concepts", result = "concept_specs" },
+ { pipe = "design_pipe_signatures", result = "pipe_signatures" },
+ { pipe = "detail_pipe_spec", batch_over = "pipe_signatures", batch_as = "pipe_signature", result = "pipe_specs" },
{ pipe = "pipe_builder_domain_information", result = "domain_information" },
- { pipe = "build_concept_spec", batch_over = "concept_spec_drafts", batch_as = "concept_spec_draft", result = "concept_specs" },
- { pipe = "create_pipes_from_signatures", batch_over = "pipe_signatures", batch_as = "pipe_signature", result = "pipe_specs" },
- { pipe = "compile_in_pipelex_bundle_spec", result = "pipelex_bundle_spec" }
- { pipe = "validate_pipelex_bundle_spec", result = "pipelex_bundle_spec" }
+ { pipe = "assemble_pipelex_bundle_spec", result = "pipelex_bundle_spec" }
+ { pipe = "assemble_pipelex_bundle_spec", result = "pipelex_bundle_spec" }
]
[pipe.pipe_builder_domain_information]
type = "PipeLLM"
-description = "Turn the brief into a DomainInformation object."
+definition = "Turn the brief into a DomainInformation object."
inputs = { brief = "UserBrief" }
output = "DomainInformation"
+llm = "llm_to_engineer"
prompt_template = """
-Based on the brief output the "domain" of this pipe, and a definition of what it would represent.
-
-Brief:
+Name and define the domain of this process:
@brief
-For example, if the pipe is about generating a compliance matrix out of a RFP, the domain would be "rfp_compliance_matrix"...
-It should be not more than 4 words, in snake_case.
-For the definition, i would like to see a short description of what the bundle would represent.
+For example, if the brief is about generating and analyzing a compliance matrix out of a RFP,
+the domain would be "rfp_compliance" and the definition would be "Generating and analyzing compliance related to RFPs".
+The domain name should be not more than 4 words, in snake_case.
+For the definition, be concise.
"""
-# ────────────────────────────────────────────────────────────────────────────────
-# STAGE 1 — plan (natural language pseudo-code, but explicit about IO + sequencing)
-# ────────────────────────────────────────────────────────────────────────────────
-
-[pipe.draft_planning_text]
+[pipe.draft_the_plan]
type = "PipeLLM"
-description = "Turn the brief into a pseudo-code plan describing controllers, pipes, their inputs/outputs."
+definition = "Turn the brief into a pseudo-code plan describing controllers, pipes, their inputs/outputs."
inputs = { brief = "UserBrief" }
-output = "PlanDraftText"
+output = "PlanDraft"
llm = "llm_to_engineer"
prompt_template = """
-Return a PlanDraftText that narrates the pipeline as pseudo-steps (no code):
-- Explicitly describe where a sequence/parallel/condition/batch is used
-- For each pipe: state the pipe's description, inputs (by name), and outputs (by name),
-- Keep it coherent: children pipes referenced by parent sequences must be named consistently
-
-
-Here is a description of the pipes:
-We have pipe controllers:
-- PipeLLM: A pipe that uses an LLM to generate a text, or a structured object. It is a vision LLM that can read images.
+Return a draft of a plan that narrates the pipeline as pseudo-steps (no code):
+- Explicitly indicate when you are running things in sequence,
+ or in parallel (several independant steps in parallel),
+ or in batch (same operation applied to N elements of a list)
+ or based on a condition
+- For each pipe: state the pipe's description, inputs (by name using snake_case), and the output (by name using snake_case),
+DO NOT indicate the inputs or output type. Just name them.
+- Be aware of the steps where you will want structured outputs or inputs. Make sense of it but be concise.
+
+Available pipe controllers:
+- PipeSequence: A pipe that executes a sequence of pipes: it needs to reference the pipes it will execute.
+- PipeParallel: A pipe that executes a few pipes in parallel. It needs to reference the pipes it will execute.
+ The results of each pipe will be in the working memory. The output MUST BE "Dynamic".
+- PipeCondition: A pipe that based on a conditional expression, branches to a specific pipe.
+ You have to explain what the expression of the condition is,
+ and reference the different pipes that well be executed according to the condition.
+
+When describing the task of a pipe controller, be concise, don't detail all the sub-pipes.
+
+Available pipe operators:
+- PipeLLM: A pipe that uses an LLM to generate a text, or a structured object. It is a vision LLM so it can also use images.
CRITICAL: When extracting MULTIPLE items (articles, employees, products), use multiple_output = true with SINGULAR concepts!
- Create concept "Article" (not "Articles") with fields "item_name", "quantity" (not "item_names", "quantities")
- Then set multiple_output = true to get a list of Article objects
-- PipeSequence: A pipe that executes a sequence of pipes: It needs to reference the pipes it will execute.
-- PipeParallel: A pipe that executes a few pipes in parallel. It needs to reference the pipes it will execute. The results of each pipe will be in the working memory. The output MUST BE "Dynamic".
-- PipeCondition: A pipe that based on a specific condition, branches to a specific pipe. You have to explain what the expression of the condition is,
- and what the different pipes are that can be executed based on the condition. It needs to reference the pipes it will execute.
-- PipeBatch: A pipe that executes a batch of pipes in parallel. It needs to reference the pipe it will execute.
-- PipeImgGen: A pipe that uses an LLM to generate an image. VERY IMPORTANT: IF YOU DECIDE TO CREATE A PIPEIMGEN, YOU ALSO HAVE TO CREATE A PIPELLM THAT WILL WRITE THE PROMPT, AND THAT NEEDS TO PRECEED THE PIPEIMGEN, based on the necessary elements.
-That means that in the MAIN pipeline, the prompt should NOT be an input. It should be a step that generates the prompt.
-- PipeOcr: A pipe that uses an OCR technology to extract text from an image.
-VERY IMPORTANT: THE INPUT OF THE PIPEOCR MUST BE either an image or a pdf or a concept which refines one of them.
-
-Be very detailed, process by steps.
-
-Brief:
-@brief
-
-LIMIT TO 10 DIFFERENT PIPES FOR NOW
-"""
-
-# ────────────────────────────────────────────────────────────────────────────────
-# STAGE 2 — textual specs (still TEXT, not structured objects yet)
-# ────────────────────────────────────────────────────────────────────────────────
-[pipe.parallel_draft_to_specs]
-type = "PipeParallel"
-description = "Generate ConceptSpecDraftsText and PipeSignaturesText in parallel from plan draft."
-inputs = { plan_draft = "PlanDraftText", brief = "UserBrief" }
-output = "Dynamic"
-parallels = [
- { pipe = "draft_to_conceptspecs_text", result = "concept_spec_drafts_text" },
- { pipe = "draft_to_pipesignatures_text", result = "pipe_signatures_text" },
-]
-add_each_output = true
-
-[pipe.draft_to_conceptspecs_text]
-type = "PipeLLM"
-description = "From PlanDraftText (+ brief), extract ConceptSpecsText (codes, descriptions, structure hints) in TEXT."
-inputs = { plan_draft = "PlanDraftText", brief = "UserBrief" }
-output = "Text"
-llm = "llm_to_engineer"
-prompt_template = """
-You will receive a plan for a Pipelex pipeline.
-Each pipeline will take inputs and output. Those inputs/output are represented as concepts.
+- PipeImgGen: A pipe that uses an AI model to generate an image.
+ VERY IMPORTANT: IF YOU DECIDE TO CREATE A PipeImgGen, YOU ALSO HAVE TO CREATE A PIPELLM THAT WILL WRITE THE PROMPT, AND THAT NEEDS TO PRECEED THE PIPEIMGEN, based on the necessary elements.
+ That means that in the MAIN pipeline, the prompt MUST NOT be considered as an input. It should be the output of a step that generates the prompt.
+- PipeOcr: A pipe that uses an OCR technology to extract text from an image or a pdf.
+ VERY IMPORTANT: THE INPUT OF THE PIPEOCR MUST BE either an image or a pdf or a concept which refines one of them.
-Return ConceptSpecsText capturing all concepts used in the plan:
-- Use PascalCase for concept codes
-- Provide a short description per concept
-- Include structure hints as plain text (fields, types) IF IT IS needed.
-CRITICAL RULE: Concepts must represent SINGLE ENTITIES, never collections!
-- Create "Article" not "Articles"
-- Create "Employee" not "Employees"
-- Use SINGULAR field names: "item_name" not "item_names", "quantity" not "quantities"
-- If you need multiple items, the PipeLLM will use multiple_output=true to generate a LIST of the concept
+Be smart about splitting the workflow into steps (sequence or parallel):
+- You can use an LLM to extract or analyze several things at the same time, they can be output as a single concept which will be structured with attributes etc.
+- But don't ask the LLM for many things which are unrelated, it would lose reliability.
-If you need structure for your concept, to isolate/extract some precise information, assign a structure:
-Here is how the structure as to be described:
-A dict with:
-- key: the field name in snake_case (ALWAYS SINGULAR)
-- value: a dict with:
- - definition: the definition of the field, in natural language
- - type: the type of the field (text, integer, boolean, number)
- - required: whether the field is required
- - default_value: the default value of the field
-
-You can have multiple fields if needed, but each field should represent a single value.
-
-Otherwise, there are native concepts that you can use:
-If the concept you want to create is JUST a text, assign "Text" to the 'refines' field, and no structure field.
-If the concept you want to create is JUST an image, assign "Image" to the 'refines' field, and no structure field.
-If the concept you want to create is JUST a PDF, assign "PDF" to the 'refines' field, and no structure field.
-If the concept you want to create is JUST a Number, assign "Number" to the 'refines' field, and no structure field.
-
-DO NOT redefine native concepts:
-- Text
-- Image
-- PDF
-- Number
-- Page
-If you need one of these, you will later on use them, but you should NOT REDEFINE THEM.
-Plan:
-@plan_draft
+Keep your style concise, no need to write tags such as "Description:", just write what you need to write.
+Do not write any intro or outro, just write the plan.
-Brief:
@brief
-
-Remember: Create concepts for SINGLE entities. Lists are handled by PipeLLM with multiple_output=true.
"""
-[pipe.draft_to_pipesignatures_text]
+[pipe.draft_the_concepts]
type = "PipeLLM"
-description = "From PlanDraftText (+ brief), extract PipeSignaturesText in TEXT."
-inputs = { plan_draft = "PlanDraftText", brief = "UserBrief" }
-output = "Text"
+definition = "Interpret the draft of a plan to create an AI pipeline, and define the needed concepts."
+inputs = { plan_draft = "PlanDraft", brief = "UserBrief" }
+output = "ConceptDrafts"
llm = "llm_to_engineer"
prompt_template = """
-Return PipeSignaturesText listing every pipe to build:
-- For each pipe: give a unique snake_case pipe_code, type, definition, inputs (by concept code/name), output, and important_features
-- Controller pipes must reference children by their codes consistently
-- The Pipe Controllers, if they mention pipes, they should always mention existing pipes.
-- Add as much details as possible for the description.
-
-Here are the ESSENTIAL features for each pipe type that should be included in important_features (only include these key ones):
-
-**PipeLLM**: A pipe that uses an LLM to generate a text, or a structured object. It is a vision LLM that can read images.
-The inputs of the PipeLLM should be:
-The variables tagged in the prompt template (with $ or @). If there are no variables, the inputs should be empty.
-The ouput should be the concept code of the output
-- prompt_template: The prompt template with variable substitution ($ for inline, @ for blocks)
-- multiple_output: true if generating multiple number of outputs: That means it will output a LIST of the CONCEPT!
-
-CRITICAL RULE FOR PIPELLM:
-- If extracting MULTIPLE items (like multiple articles, employees, products), use multiple_output = true
-- The concept should represent ONE SINGLE item (Article, Employee, Product)
-- DO NOT create concepts with plural field names like "item_names", "quantities"
-- Instead: use multiple_output = true with singular concept fields like "item_name", "quantity"
-- Example: To extract multiple articles, create concept "Article" with fields "item_name", "quantity", then use multiple_output = true
-
-**PipeSequence**: A pipe that executes a sequence of pipes: It needs to reference the pipes it will execute.
-The inputs of the PipeSequence should be all the necessary inputs in the below steps, and the inputs that are NOT generated by intermediate steps.
-The output should be the concept code of the output of the last step.
-- steps: List of pipe codes to execute in order, with result names
-- Each step format: {"pipe": "pipe_code", "result": "result_name"}
-- Can include batch operations: {"pipe": "pipe_code", "batch_over": "list_input", "batch_as": "item_name", "result": "result_name"}
-
-**PipeParallel**: A pipe that executes a few pipes in parallel. It needs to reference the pipes it will execute.
-The inputs of the PipeParallel should be all the necessary inputs in the below steps
-The output should be the concept code of the output of the last step.
-The results of each pipe will be in the working memory.
-- parallels: List of pipes to execute in parallel
-- Each parallel format: {"pipe": "pipe_code", "result": "result_name"}
-
-**PipeCondition**: A pipe that based on a specific condition, branches to a specific pipe. You have to explain what the expression of the condition is,
- and what the different pipes are that can be executed based on the condition. It needs to reference the pipes it will execute.
-The inputs of the PipeCondition should be all the necessary inputs in the below steps
-The output should be the concept code of the output of all the steps, except if the outputs are different, then its "Dynamic"
-- expression: Direct expression to evaluate (e.g., "task_result.status")
-- pipe_map: Dictionary mapping condition results to pipe codes (e.g., {"completed": "success_pipe", "failed": "failure_pipe"})
-- default_pipe_code: Fallback pipe when no conditions match
-
-**PipeBatch**: A pipe that executes a batch of pipes in parallel. It needs to reference the pipe it will execute.
-- branch_pipe_code: The pipe code to execute for each item
-- input_list_name: Name of the list to iterate over
-- input_item_name: Name for individual items within each execution
-
-**PipeImgGen**: A pipe that uses an LLM to generate an image.
-The inputs of the PipeImgGen should be: {prompt: ImgGenPrompt}
-The output should be the concept code that refines Image.
-- img_gen_prompt: Static prompt for image generation (if using static prompt)
-- nb_output: Number of images to generate (default 1)
-VERY IMPORTANT: IF YOU DECIDE TO CREATE A PIPEIMGEN, YOU ALSO HAVE TO CREATE A PIPELLM THAT WILL WRITE THE PROMPT, AND THAT NEEDS TO PRECEED THE PIPEIMGEN, based on the necessary elements.
-THERFORE, the OUTPUT OF THIS PIPELLM should be a VARIABLE NAMED "prompt" that will be used as input for the PipeImgGen.
-That means that in the MAIN pipeline, the prompt should NOT be an input. It should be a step that generates the prompt.
-
-**PipeOcr**: A pipe that uses an LLM to extract text from an image.
-- The INPUTS of PipeOcr must be either an image or a pdf or a concept which refines one of them.
-
-**PipeFunc**: A pipe that executes a custom Python function.
-- function_name: Name of the Python function to call
+We are working on writing an AI pipeleine to fulfill this brief:
+@brief
-**PipeCompose**: A pipe that uses Jinja2 to render a template.
-- jinja2: Raw Jinja2 template string OR
-- jinja2_name: Name reference to a template (use one or the other)
+We have already written a plan for the pipeline. It's built using pipes, each with its own inputs (one or more) and output (single).
+Variables are snake_case and concepts are PascalCase.
+
+Your job is to clarify the different concepts used in the plan.
+We want clear concepts but we don't want too many concepts. If a concept can be reused in the pipeline, it's the same concept.
+For instance:
+- If you have a "FlowerDescription" concept, then it can be used for rose_description, tulip_description, beautiful_flower_description, dead_flower_description, etc.
+- DO NOT define concepts that include adjectives: "LongArticle" is wrong, "Article" is right.
+- DO NOT include circumstances in the concept definition:
+ "ArticleAboutApple" is wrong, "Article" is right.
+ "CounterArgument" is wrong, "Argument" is right.
+- Concepts are always expressed as singular nouns, even if we're to use them as a list:
+ for instance, define the concept as "Article" not "Articles", "Employee" not "Employees".
+ If we need multiple items, we'll indicate it elsewhere so you don't bother with it here.
+- Provide a short description concise description for each concept
+
+If the concept can be expressed as a text, image, pdf, number, or page:
+- Name the concept, define it and just write "refines: Text", "refines: PDF", or "refines: Image" etc.
+- No need to define its structure
+Else, if you need structure for your concept, draft its structure:
+- field name in snake_case
+- definition:
+ - definition: the definition of the field, in natural language
+ - type: the type of the field (text, integer,boolean, number, date)
+ - required: add required = true if the field is required (otherwise, leave it empty)
+ - default_value: the default value of the field
-Plan:
@plan_draft
-Brief:
-@brief
+DO NOT redefine native concepts such as: Text, Image, PDF, Number, Page. if you need one of these, they already exist so you should NOT REDEFINE THEM.
-No more than 10 PipeSignatures
+Do not write any intro or outro, do not mention the brief or the plan draft, just write the concept drafts.
+List the concept drafts in Markdown format with a heading 3 for each, e.g. `### Concept FooBar`.
"""
-# ────────────────────────────────────────────────────────────────────────────────
-# STAGE 3 — materialize: TEXT → real objects (ConceptSpec[], PipeSignature[])
-# ────────────────────────────────────────────────────────────────────────────────
-
-[pipe.materialize_concept_spec_drafts]
+[pipe.structure_concepts]
type = "PipeLLM"
-description = "Turn ConceptSpecsText into ConceptSpec objects."
-inputs = { concept_spec_drafts_text = "Text", brief = "UserBrief" }
-output = "concept.ConceptSpecDraft"
+definition = "Structure the concept definitions."
+inputs = { concept_drafts = "ConceptDrafts", brief = "UserBrief" }
+output = "concept.ConceptSpec"
multiple_output = true
llm = "llm_to_engineer"
+system_prompt = """
+You are an expert at data extraction and json formatting.
+"""
prompt_template = """
-Materialize ConceptSpec objects from the ConceptSpecsText.
-Do not change the information in the input. Just organize the information
-
-ConceptSpecs:
-@concept_spec_drafts_text
+Your job is to extract a list of ConceptSpec from these concept drafts:
-Brief:
-@brief
-
-LIMIT TO A MAXIMUM OF 5 fields for now
+@concept_drafts
"""
-[pipe.materialize_pipe_signatures]
+[pipe.design_pipe_signatures]
type = "PipeLLM"
-description = "Turn PipeSignaturesText into PipeSignature objects that reference the ConceptSpec objects."
-inputs = { pipe_signatures_text = "Text", concept_spec_drafts = "concept.ConceptSpecDraft", brief = "UserBrief" }
-output = "pipe.PipeSignature"
+definition = "Write the pipe signatures for the plan."
+inputs = { plan_draft = "PlanDraft", brief = "UserBrief", concept_specs = "concept.ConceptSpec" }
+output = "pipe_design.PipeSignature"
multiple_output = true
llm = "llm_to_engineer"
+system_prompt = """
+You are a Senior engineer, very well versed in creating pipelines.
+You are very thorough about naming stuff, structured and rigorous in your planning.
+"""
prompt_template = """
-Materialize PipeSignature objects from the PipeSignaturesText.
-- pipe_code MUST be snake_case
-- inputs must be a Dict[str, ConceptSpecDraft] referencing the provided ConceptSpecDraft objects. If Its the concept itself, use the concept code in PascalCase.
-- output must be a ConceptSpec from the provided set. If Its the concept itself, use the concept code in PascalCase.
-- important_features must be a Dict containing the pipe-specific features mentioned in the text
+Your job is to structure the required PipeSignatures for defining a pipeline which has already been drafted.
-VERY IMPORTANT: A pipe has inputs, and an output. The inputs are a dict of keys in snake_case, corresponding to the variables names in the working memory, and the values are the concept codes in PascalCase.
-The output is a concept code in PascalCase.
-The field "result" is corresponding to the name of the result of the pipe. It will be used in the inputs of the next pipes.
-It is important that they link each other in the right way.
-
-The output concept should be a concepts should be in PascalCase
-
-IMPORTANT:
-- THE MAIN PIPE SHOULD CONTAIN IN ITS NAME "main_pipeline"
-- IF THERE IS A PipeIMG, VERIFIES THAT THE INPUT PROMPT IS ACTUALLY GENERATED BY A PIPELLM BEFORE THE PIPEIMG.
-THIS PIPELLM SHOULD NAME THE RESULT OF ITS PIPE "prompt".
-
-PipeSignatures:
-@pipe_signatures_text
-
-ConceptSpecDrafts:
-@concept_spec_drafts
-
-Brief:
@brief
-No more than 10 PipeSignatures
-"""
-
-[pipe.compile_in_pipelex_bundle_spec]
-type = "PipeFunc"
-description = "Compile the pipelex bundle spec."
-inputs = { pipe_specs = "PipeSpec", concept_specs = "ConceptSpec" }
-output = "PipelexBundleSpec"
-function_name = "compile_in_pipelex_bundle_spec"
-
-[pipe.validate_pipelex_bundle_spec]
-type = "PipeSequence"
-description = "Validate the pipelex bundle spec with iterative fixing."
-inputs = { pipelex_bundle_spec = "PipelexBundleSpec" }
-output = "PipelexBundleSpec"
-steps = [
- { pipe = "validate_dry_run", result = "failed_pipes" },
- { pipe = "check_validation_status", result = "validation_status" },
- { pipe = "handle_validation_result", result = "pipelex_bundle_spec" }
-]
+@plan_draft
-[pipe.check_validation_status]
-type = "PipeCompose"
-description = "Check if validation failed by examining if failed_pipes list is empty."
-inputs = { failed_pipes = "PipeFailure" }
-output = "Text"
-jinja2 = "{% if failed_pipes.content.items|length > 0 %}FAILURE{% else %}SUCCESS{% endif %}"
+{% if concept_specs %}
+We have already defined the concepts you can use for inputs/outputs:
+@concept_specs
+And of course you still have the native concepts if required: Text, Image, PDF, Number, Page.
+{% else %}
+You can use the native concepts for inputs/outputs as required: Text, Image, PDF, Number, Page.
+{% endif %}
-[pipe.handle_validation_result]
-type = "PipeCondition"
-description = "Handle validation result - continue if success or fix failures once."
-inputs = { pipelex_bundle_spec = "PipelexBundleSpec", failed_pipes = "PipeFailure", validation_status = "Text" }
-output = "PipelexBundleSpec"
-expression = "validation_status.text"
+Define the contracts of the pipes to build:
+- For each pipe: give a unique snake_case pipe_code, a type and description, specify inputs (one or more) and output (one)
+- Add as much details as possible for the description.
-[pipe.handle_validation_result.pipe_map]
-SUCCESS = "continue"
-FAILURE = "fix_failing_pipes_once"
+Available pipe controllers:
+- PipeSequence: A pipe that executes a sequence of pipes: it needs to reference the pipes it will execute.
+- PipeParallel: A pipe that executes a few pipes in parallel. It needs to reference the pipes it will execute.
+ The results of each pipe will be in the working memory. The output MUST BE "Dynamic".
+- PipeCondition: A pipe that based on a conditional expression, branches to a specific pipe.
+ You have to explain what the expression of the condition is,
+ and reference the different pipes that well be executed according to the condition.
-[pipe.fix_failing_pipes_once]
-type = "PipeSequence"
-description = "Fix failing pipes once and return the result."
-inputs = { pipelex_bundle_spec = "PipelexBundleSpec", failed_pipes = "PipeFailure" }
-output = "PipelexBundleSpec"
-steps = [
- { pipe = "fix_failing_pipe", batch_over = "failed_pipes", batch_as = "failed_pipe", result = "fixed_pipes" },
- { pipe = "reconstruct_bundle_with_all_fixes", result = "pipelex_bundle_spec" },
- { pipe = "validate_pipelex_bundle_spec", result = "pipelex_bundle_spec" }
-]
-
-[pipe.validate_dry_run]
-type = "PipeFunc"
-description = "Validate the pipelex bundle spec and return only failed pipes."
-inputs = { pipelex_bundle_spec = "PipelexBundleSpec" }
-output = "PipeFailure"
-function_name = "validate_dry_run"
+When describing the task of a pipe controller, be concise, don't detail all the sub-pipes.
-[pipe.continue]
-type = "PipeCompose"
-description = "Continue with successful validation - return the bundle unchanged."
-inputs = { pipelex_bundle_spec = "PipelexBundleSpec" }
-output = "PipelexBundleSpec"
-jinja2 = "{{ pipelex_bundle_spec }}"
+Available pipe operators:
+- PipeLLM: A pipe that uses an LLM to generate a text, or a structured object. It is a vision LLM so it can also use images.
+ CRITICAL: When extracting MULTIPLE items (articles, employees, products), use multiple_output = true with SINGULAR concepts!
+ - Create concept "Article" (not "Articles") with fields "item_name", "quantity" (not "item_names", "quantities")
+ - Then set multiple_output = true to get a list of Article objects
+- PipeImgGen: A pipe that uses an AI model to generate an image.
+ VERY IMPORTANT: IF YOU DECIDE TO CREATE A PipeImgGen, YOU ALSO HAVE TO CREATE A PIPELLM THAT WILL WRITE THE PROMPT, AND THAT NEEDS TO PRECEED THE PIPEIMGEN, based on the necessary elements.
+ That means that in the MAIN pipeline, the prompt MUST NOT be considered as an input. It should be the output of a step that generates the prompt.
+- PipeOcr: A pipe that extracts text from an image or a pdf. PipeOcr must have a exactly one input which must be either an `Image` or a `PDF`.
+
+Be smart about splitting the workflow into steps (sequence or parallel):
+- You can use an LLM to extract or analyze several things at the same time, they can be output as a single concept which will be structured with attributes etc.
+- But don't ask the LLM for many things which are unrelated, it would lose reliability.
+"""
-[pipe.reconstruct_bundle_with_all_fixes]
+[pipe.assemble_pipelex_bundle_spec]
type = "PipeFunc"
-description = "Reconstruct the bundle spec with all the fixed pipes."
-inputs = { pipelex_bundle_spec = "PipelexBundleSpec", fixed_pipes = "Dynamic" }
+definition = "Compile the pipelex bundle spec."
+inputs = { pipe_specs = "PipeSpec", concept_specs = "ConceptSpec", domain_information = "DomainInformation" }
output = "PipelexBundleSpec"
-function_name = "reconstruct_bundle_with_all_fixes"
-
+function_name = "assemble_pipelex_bundle_spec"
diff --git a/pipelex/libraries/pipelines/builder/builder.py b/pipelex/libraries/pipelines/builder/builder.py
index 4493cf68d..026fe70d6 100644
--- a/pipelex/libraries/pipelines/builder/builder.py
+++ b/pipelex/libraries/pipelines/builder/builder.py
@@ -7,7 +7,27 @@ from pipelex.core.concepts.concept_blueprint import ConceptBlueprint
from pipelex.core.domains.domain_blueprint import DomainBlueprint
from pipelex.core.memory.working_memory import WorkingMemory
from pipelex.core.stuffs.stuff_content import ListContent, StructuredContent
+from pipelex.exceptions import (
+ ConceptLoadingError,
+ DomainLoadingError,
+ PipeLoadingError,
+ StaticValidationError,
+)
from pipelex.hub import get_library_manager
+from pipelex.libraries.pipelines.builder.builder_errors import (
+ ConceptDefinitionErrorData,
+ ConceptFailure,
+ ConceptSpecError,
+ DomainFailure,
+ PipeBuilderError,
+ PipeDefinitionErrorData,
+ PipeFailure,
+ PipelexBundleError,
+ PipelexBundleUnexpectedError,
+ PipeSpecError,
+ StaticValidationErrorData,
+ ValidateDryRunError,
+)
from pipelex.libraries.pipelines.builder.concept.concept_spec import ConceptSpec
from pipelex.libraries.pipelines.builder.pipe.pipe_batch_spec import PipeBatchSpec
from pipelex.libraries.pipelines.builder.pipe.pipe_compose_spec import PipeComposeSpec
@@ -18,30 +38,13 @@ from pipelex.libraries.pipelines.builder.pipe.pipe_llm_spec import PipeLLMSpec
from pipelex.libraries.pipelines.builder.pipe.pipe_ocr_spec import PipeOcrSpec
from pipelex.libraries.pipelines.builder.pipe.pipe_parallel_spec import PipeParallelSpec
from pipelex.libraries.pipelines.builder.pipe.pipe_sequence_spec import PipeSequenceSpec
-from pipelex.libraries.pipelines.builder.pipe.pipe_signature import PipeSignature
from pipelex.pipe_works.pipe_dry import dry_run_pipes
-from pipelex.tools.typing.pydantic_utils import empty_list_factory_of, format_pydantic_validation_error
-from pipelex.types import StrEnum
+from pipelex.tools.typing.pydantic_utils import format_pydantic_validation_error
class DomainInformation(StructuredContent):
- domain: str = Field(description="The domain of the pipeline library.")
- definition: str = Field(description="The definition of the pipeline library.")
-
-
-class PipeBuilderError(Exception):
- pass
-
-
-class PipelexBundleSpecDraft(StructuredContent):
- """Complete spec of a pipeline library TOML file."""
-
- domain: str = Field(description="The domain of the pipeline library.")
- definition: str = Field(description="The definition of the pipeline library.")
-
- concept: dict[str, ConceptSpec] = Field(default_factory=dict, description="The concepts of the pipeline library.")
-
- pipe: dict[str, PipeSignature] = Field(default_factory=dict, description="The pipes of the pipeline library.")
+ domain: str = Field(description="Name of the domain of the knowledge work.")
+ definition: str = Field(description="Definition of the domain of the knowledge work.")
PipeSpecUnion = Annotated[
@@ -96,8 +99,6 @@ class PipelexBundleSpec(StructuredContent):
domain: str
definition: str | None = None
system_prompt: str | None = None
- system_prompt_to_structure: str | None = None
- prompt_template_to_structure: str | None = None
concept: dict[str, ConceptSpec | str] | None = Field(default_factory=dict)
@@ -114,24 +115,34 @@ class PipelexBundleSpec(StructuredContent):
if self.concept:
concept = {}
- for concept_code, concept_blueprint in self.concept.items():
- if isinstance(concept_blueprint, ConceptSpec):
- concept[concept_code] = concept_blueprint.to_blueprint()
+ for concept_code, concept_spec_or_name in self.concept.items():
+ if isinstance(concept_spec_or_name, ConceptSpec):
+ try:
+ concept[concept_code] = concept_spec_or_name.to_blueprint()
+ except ValidationError as 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 exc
else:
- concept[concept_code] = ConceptBlueprint(definition=concept_code, structure=concept_blueprint)
+ concept[concept_code] = ConceptBlueprint(definition=concept_code, structure=concept_spec_or_name)
pipe: dict[str, PipeBlueprintUnion] | None = None
if self.pipe:
pipe = {}
- for pipe_code, pipe_blueprint in self.pipe.items():
- pipe[pipe_code] = pipe_blueprint.to_blueprint()
+ for pipe_code, pipe_spec in self.pipe.items():
+ try:
+ pipe[pipe_code] = pipe_spec.to_blueprint()
+ except ValidationError as 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 exc
return PipelexBundleBlueprint(
domain=self.domain,
definition=self.definition,
- prompt_template_to_structure=self.prompt_template_to_structure,
+ prompt_template_to_structure=None,
system_prompt=self.system_prompt,
- system_prompt_to_structure=self.system_prompt_to_structure,
+ system_prompt_to_structure=None,
pipe=pipe,
concept=concept,
)
@@ -158,7 +169,7 @@ def _convert_pipe_spec(pipe_spec: PipeSpecUnion) -> PipeSpecUnion:
return cast("PipeSpecUnion", pipe_class(**pipe_spec.model_dump(serialize_as_any=True)))
-async def compile_in_pipelex_bundle_spec(working_memory: WorkingMemory) -> PipelexBundleSpec:
+async def assemble_pipelex_bundle_spec(working_memory: WorkingMemory) -> PipelexBundleSpec:
"""Construct a PipelexBundleSpec from working memory containing concept and pipe blueprints.
Args:
@@ -198,41 +209,66 @@ async def compile_in_pipelex_bundle_spec(working_memory: WorkingMemory) -> Pipel
)
-# TODO: rename or merge with PipeDry.DryRunStatus
-class DryRunStatus(StrEnum):
- SUCCESS = "SUCCESS"
- FAILURE = "FAILURE"
-
-
-class ValidateDryRunError(Exception):
- """Raised when validating the dry run of a pipelex bundle blueprint."""
-
-
-class PipeFailure(StructuredContent):
- """Details of a single pipe failure during dry run."""
-
- pipe: PipeSpecUnion = Field(description="The failing pipe spec blueprint with pipe code")
- error_message: str = Field(description="The error message for this pipe")
-
-
-class DryRunResult(StructuredContent):
- """A result of a dry run of a pipelex bundle blueprint."""
-
- status: DryRunStatus
- failed_pipes: list[PipeFailure] = Field(
- default_factory=empty_list_factory_of(PipeFailure),
- description="List of pipes that failed during dry run",
- )
-
-
-async def validate_dry_run(working_memory: WorkingMemory) -> ListContent[PipeFailure]:
+async def validate_bundle_spec_from_memory(working_memory: WorkingMemory):
pipelex_bundle_spec = working_memory.get_stuff_as(name="pipelex_bundle_spec", content_type=PipelexBundleSpec)
- pipelex_bundle_blueprint = pipelex_bundle_spec.to_blueprint()
+ await validate_bundle_spec(pipelex_bundle_spec=pipelex_bundle_spec)
+
+async def validate_bundle_spec(pipelex_bundle_spec: PipelexBundleSpec):
library_manager = get_library_manager()
+ try:
+ 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
+
+ try:
+ pipes = library_manager.load_from_blueprint(blueprint=pipelex_bundle_blueprint)
+ dry_run_result = await dry_run_pipes(pipes=pipes, raise_on_failure=True)
+ except StaticValidationError as static_validation_error:
+ static_validation_error_data = StaticValidationErrorData(
+ error_type=static_validation_error.error_type,
+ domain=static_validation_error.domain,
+ pipe_code=static_validation_error.pipe_code,
+ variable_names=static_validation_error.variable_names,
+ required_concept_codes=static_validation_error.required_concept_codes,
+ provided_concept_code=static_validation_error.provided_concept_code,
+ file_path=static_validation_error.file_path,
+ explanation=static_validation_error.explanation,
+ )
+ raise PipelexBundleError(
+ message=static_validation_error.desc(), static_validation_error=static_validation_error_data
+ ) 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:
+ concept_def_error = concept_loading_error.concept_definition_error
+ concept_definition_error_data = ConceptDefinitionErrorData(
+ message=str(concept_def_error),
+ domain_code=concept_def_error.domain_code,
+ concept_code=concept_def_error.concept_code,
+ description=concept_def_error.description,
+ structure_class_python_code=concept_def_error.structure_class_python_code,
+ source=concept_def_error.source,
+ )
+ raise PipelexBundleError(
+ message=concept_loading_error.message, concept_definition_errors=[concept_definition_error_data]
+ ) from concept_loading_error
+ except PipeLoadingError as pipe_loading_error:
+ pipe_def_error = pipe_loading_error.pipe_definition_error
+ pipe_definition_error_data = PipeDefinitionErrorData(
+ message=str(pipe_def_error),
+ domain_code=pipe_def_error.domain_code,
+ pipe_code=pipe_def_error.pipe_code,
+ description=pipe_def_error.description,
+ source=pipe_def_error.source,
+ )
+ raise PipelexBundleError(message=pipe_loading_error.message, pipe_definition_errors=[pipe_definition_error_data]) 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 = {
@@ -247,35 +283,71 @@ async def validate_dry_run(working_memory: WorkingMemory) -> ListContent[PipeFai
"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:
+ 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)
+
pipe_spec = pipelex_bundle_spec.pipe[pipe_code]
spec_class = pipe_type_to_spec_class.get(pipe_spec.type)
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(
- PipeFailure(
- pipe=pipe_spec,
- error_message=dry_run_output.error_message or "",
- ),
+ pipe_failure = PipeFailure(
+ pipe_spec=pipe_spec,
+ error_message=dry_run_output.error_message or "",
)
-
- return ListContent[PipeFailure](items=failed_pipes)
+ dry_run_pipe_failures.append(pipe_failure)
+ if dry_run_pipe_failures:
+ raise PipelexBundleError(message="Pipes failed during dry run", pipe_failures=dry_run_pipe_failures)
-async def reconstruct_bundle_with_all_fixes(working_memory: WorkingMemory) -> PipelexBundleSpec:
+async def reconstruct_bundle_with_pipe_fixes_from_memory(working_memory: WorkingMemory) -> PipelexBundleSpec:
pipelex_bundle_spec = working_memory.get_stuff_as(name="pipelex_bundle_spec", content_type=PipelexBundleSpec)
fixed_pipes_list = cast("ListContent[PipeSpecUnion]", working_memory.get_stuff(name="fixed_pipes").content)
+ return await reconstruct_bundle_with_pipe_fixes(pipelex_bundle_spec=pipelex_bundle_spec, fixed_pipes=fixed_pipes_list.items)
+
+async def reconstruct_bundle_with_pipe_fixes(pipelex_bundle_spec: PipelexBundleSpec, fixed_pipes: list[PipeSpecUnion]) -> PipelexBundleSpec:
if not pipelex_bundle_spec.pipe:
msg = "No pipes section found in bundle spec"
raise PipeBuilderError(msg)
- for fixed_pipe_blueprint in fixed_pipes_list.items:
+ for fixed_pipe_blueprint in fixed_pipes:
pipe_code = fixed_pipe_blueprint.the_pipe_code
pipelex_bundle_spec.pipe[pipe_code] = fixed_pipe_blueprint
return pipelex_bundle_spec
+
+
+async def reconstruct_bundle_with_all_fixes(working_memory: WorkingMemory) -> PipelexBundleSpec:
+ pipelex_bundle_spec = working_memory.get_stuff_as(name="pipelex_bundle_spec", content_type=PipelexBundleSpec)
+ if fixed_pipes := working_memory.get_optional_stuff(name="fixed_pipes"):
+ fixed_pipes_list = cast("ListContent[PipeSpecUnion]", fixed_pipes.content)
+
+ if not pipelex_bundle_spec.pipe:
+ msg = "No pipes section found in bundle spec"
+ raise PipeBuilderError(msg)
+
+ for fixed_pipe_blueprint in fixed_pipes_list.items:
+ pipe_code = fixed_pipe_blueprint.the_pipe_code
+ pipelex_bundle_spec.pipe[pipe_code] = fixed_pipe_blueprint
+
+ if fixed_concepts := working_memory.get_optional_stuff(name="fixed_concepts"):
+ fixed_concepts_list = cast("ListContent[ConceptSpec]", fixed_concepts.content)
+
+ if not pipelex_bundle_spec.concept:
+ msg = "No concepts section found in bundle spec"
+ raise PipeBuilderError(msg)
+
+ for fixed_concept_blueprint in fixed_concepts_list.items:
+ concept_code = fixed_concept_blueprint.the_concept_code
+ pipelex_bundle_spec.concept[concept_code] = fixed_concept_blueprint
+
+ return pipelex_bundle_spec
diff --git a/pipelex/libraries/pipelines/builder/builder_errors.py b/pipelex/libraries/pipelines/builder/builder_errors.py
new file mode 100644
index 000000000..0568c0e6f
--- /dev/null
+++ b/pipelex/libraries/pipelines/builder/builder_errors.py
@@ -0,0 +1,190 @@
+"""Error classes and their structured content representations for the builder domain."""
+
+from pydantic import Field
+
+from pipelex.core.stuffs.stuff_content import StructuredContent
+from pipelex.exceptions import (
+ PipelexError,
+ StaticValidationErrorType,
+)
+from pipelex.libraries.pipelines.builder.concept.concept_spec import ConceptSpec
+from pipelex.libraries.pipelines.builder.pipe.pipe_batch_spec import PipeBatchSpec
+from pipelex.libraries.pipelines.builder.pipe.pipe_compose_spec import PipeComposeSpec
+from pipelex.libraries.pipelines.builder.pipe.pipe_condition_spec import PipeConditionSpec
+from pipelex.libraries.pipelines.builder.pipe.pipe_func_spec import PipeFuncSpec
+from pipelex.libraries.pipelines.builder.pipe.pipe_img_spec import PipeImgGenSpec
+from pipelex.libraries.pipelines.builder.pipe.pipe_llm_spec import PipeLLMSpec
+from pipelex.libraries.pipelines.builder.pipe.pipe_ocr_spec import PipeOcrSpec
+from pipelex.libraries.pipelines.builder.pipe.pipe_parallel_spec import PipeParallelSpec
+from pipelex.libraries.pipelines.builder.pipe.pipe_sequence_spec import PipeSequenceSpec
+from pipelex.types import Self
+
+# Type alias for pipe spec union
+PipeSpecUnion = (
+ PipeFuncSpec
+ | PipeImgGenSpec
+ | PipeComposeSpec
+ | PipeLLMSpec
+ | PipeOcrSpec
+ | PipeBatchSpec
+ | PipeConditionSpec
+ | PipeParallelSpec
+ | PipeSequenceSpec
+)
+
+
+# ============================================================================
+# BaseModel (StructuredContent) versions of error information
+# ============================================================================
+
+
+class StaticValidationErrorData(StructuredContent):
+ """Structured data for StaticValidationError."""
+
+ error_type: StaticValidationErrorType = Field(description="The type of static validation error")
+ domain: str = Field(description="The domain where the error occurred")
+ pipe_code: str | None = Field(None, description="The pipe code if applicable")
+ variable_names: list[str] | None = Field(None, description="Variable names involved in the error")
+ required_concept_codes: list[str] | None = Field(None, description="Required concept codes")
+ provided_concept_code: str | None = Field(None, description="The provided concept code")
+ file_path: str | None = Field(None, description="The file path where the error occurred")
+ explanation: str | None = Field(None, description="Additional explanation of the error")
+
+
+class ConceptDefinitionErrorData(StructuredContent):
+ """Structured data for ConceptDefinitionError."""
+
+ message: str = Field(description="The error message")
+ domain_code: str = Field(description="The domain code")
+ concept_code: str = Field(description="The concept code")
+ description: str = Field(description="Description of the concept")
+ structure_class_python_code: str | None = Field(None, description="Python code for the structure class if available")
+ source: str | None = Field(None, description="Source of the error")
+
+
+class PipeDefinitionErrorData(StructuredContent):
+ """Structured data for PipeDefinitionError."""
+
+ message: str = Field(description="The error message")
+ domain_code: str | None = Field(None, description="The domain code")
+ pipe_code: str | None = Field(None, description="The pipe code")
+ description: str | None = Field(None, description="Description of the pipe")
+ source: str | None = Field(None, description="Source of the error")
+
+
+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")
+
+
+class ConceptFailure(StructuredContent):
+ """Details of a single concept failure during dry run."""
+
+ concept_spec: ConceptSpec = Field(description="The failing concept spec with concept code")
+ error_message: str = Field(description="The error message for this concept")
+
+
+class PipeFailure(StructuredContent):
+ """Details of a single pipe failure during dry run."""
+
+ pipe_spec: (
+ PipeFuncSpec
+ | PipeImgGenSpec
+ | PipeComposeSpec
+ | PipeLLMSpec
+ | PipeOcrSpec
+ | PipeBatchSpec
+ | PipeConditionSpec
+ | PipeParallelSpec
+ | PipeSequenceSpec
+ ) = Field(description="The failing pipe spec with pipe code")
+ error_message: str = Field(description="The error message for this pipe")
+
+
+class PipelexBundleErrorData(StructuredContent):
+ """Structured data for PipelexBundleError."""
+
+ message: str = Field(description="The main error message")
+ static_validation_error: StaticValidationErrorData | None = Field(None, description="Static validation error if present")
+ domain_failures: list[DomainFailure] | None = Field(None, description="List of domain failures")
+ pipe_failures: list[PipeFailure] | None = Field(None, description="List of pipe failures")
+ concept_failures: list[ConceptFailure] | None = Field(None, description="List of concept failures")
+ concept_definition_errors: list[ConceptDefinitionErrorData] | None = Field(None, description="List of concept definition errors")
+ pipe_definition_errors: list[PipeDefinitionErrorData] | None = Field(None, description="List of pipe definition errors")
+
+
+# ============================================================================
+# Exception classes with as_structured_content() methods
+# ============================================================================
+
+
+class PipeBuilderError(Exception):
+ """Base exception for pipe builder errors."""
+
+
+class ConceptSpecError(PipelexError):
+ """Details of a single concept failure during dry run."""
+
+ def __init__(self: Self, message: str, concept_failure: ConceptFailure) -> None:
+ self.concept_failure = concept_failure
+ super().__init__(message)
+
+ def as_structured_content(self: Self) -> ConceptFailure:
+ """Return the concept failure as structured content."""
+ return self.concept_failure
+
+
+class PipeSpecError(PipelexError):
+ """Details of a single pipe failure during dry run."""
+
+ def __init__(self: Self, message: str, pipe_failure: PipeFailure) -> None:
+ self.pipe_failure = pipe_failure
+ super().__init__(message)
+
+ def as_structured_content(self: Self) -> PipeFailure:
+ """Return the pipe failure as structured content."""
+ return self.pipe_failure
+
+
+class ValidateDryRunError(Exception):
+ """Raised when validating the dry run of a pipe."""
+
+
+class PipelexBundleError(PipelexError):
+ """Main bundle error that aggregates multiple types of errors."""
+
+ def __init__(
+ self: Self,
+ message: str,
+ static_validation_error: StaticValidationErrorData | None = None,
+ domain_failures: list[DomainFailure] | None = None,
+ pipe_failures: list[PipeFailure] | None = None,
+ concept_failures: list[ConceptFailure] | None = None,
+ concept_definition_errors: list[ConceptDefinitionErrorData] | None = None,
+ pipe_definition_errors: list[PipeDefinitionErrorData] | None = None,
+ ) -> None:
+ 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_errors
+ super().__init__(message)
+
+ def as_structured_content(self: Self) -> PipelexBundleErrorData:
+ """Convert the error to structured content."""
+ return PipelexBundleErrorData(
+ message=str(self),
+ static_validation_error=self.static_validation_error,
+ domain_failures=self.domain_failures,
+ pipe_failures=self.pipe_failures,
+ concept_failures=self.concept_failures,
+ concept_definition_errors=self.concept_definition_errors,
+ pipe_definition_errors=self.pipe_definition_errors,
+ )
+
+
+class PipelexBundleUnexpectedError(PipelexError):
+ """Raised when an unexpected error occurs during validation."""
diff --git a/pipelex/libraries/pipelines/builder/builder_loop.py b/pipelex/libraries/pipelines/builder/builder_loop.py
new file mode 100644
index 000000000..462b5493e
--- /dev/null
+++ b/pipelex/libraries/pipelines/builder/builder_loop.py
@@ -0,0 +1,66 @@
+from pipelex import log, pretty_print
+from pipelex.client.protocol import ImplicitMemory
+from pipelex.core.pipes.pipe_blueprint import AllowedPipeCategories
+from pipelex.exceptions import StaticValidationErrorType
+from pipelex.hub import get_required_pipe
+from pipelex.language.plx_factory import PlxFactory
+from pipelex.libraries.pipelines.builder.builder import (
+ PipelexBundleSpec,
+ PipeSpecUnion,
+ reconstruct_bundle_with_pipe_fixes,
+ validate_bundle_spec,
+)
+from pipelex.libraries.pipelines.builder.builder_errors import PipelexBundleError
+from pipelex.pipeline.execute import execute_pipeline
+from pipelex.tools.misc.file_utils import save_text_to_path
+
+
+class BuilderLoop:
+ async def build_and_fix(self, pipe_code: str, input_memory: ImplicitMemory | None = None) -> PipelexBundleSpec:
+ pretty_print(f"Building and fixing with {pipe_code}")
+ pipe_output = await execute_pipeline(
+ pipe_code=pipe_code,
+ input_memory=input_memory,
+ )
+ pretty_print(pipe_output, title="Pipe Output")
+
+ pipelex_bundle_spec = pipe_output.working_memory.get_stuff_as(name="pipelex_bundle_spec", content_type=PipelexBundleSpec)
+ pretty_print(pipelex_bundle_spec, title="Pipelex Bundle Spec • 1st iteration")
+ plx_content = PlxFactory.make_plx_content(blueprint=pipelex_bundle_spec.to_blueprint())
+ save_text_to_path(text=plx_content, path="results/generated_pipeline_1st_iteration.plx")
+
+ try:
+ await validate_bundle_spec(pipelex_bundle_spec=pipelex_bundle_spec)
+ except PipelexBundleError as bundle_error:
+ pretty_print(bundle_error.as_structured_content(), title="Pipelex Bundle Error")
+ log.error("Some pipes are failing, we should fix them but it's not implemented yet: ", bundle_error.message)
+
+ fixed_pipes: list[PipeSpecUnion] = []
+
+ # Fix static validation errors for PipeController inputs
+ if bundle_error.static_validation_error:
+ static_error = bundle_error.static_validation_error
+ if static_error.error_type in (
+ StaticValidationErrorType.MISSING_INPUT_VARIABLE,
+ StaticValidationErrorType.EXTRANEOUS_INPUT_VARIABLE,
+ ):
+ if static_error.pipe_code and pipelex_bundle_spec.pipe:
+ pipe_spec = pipelex_bundle_spec.pipe.get(static_error.pipe_code)
+ if pipe_spec and pipe_spec.category == AllowedPipeCategories.PIPE_CONTROLLER:
+ pipe = get_required_pipe(pipe_code=static_error.pipe_code)
+ needed_inputs = pipe.needed_inputs()
+ # Build the new inputs dict from needed_inputs
+ new_inputs: dict[str, str] = {}
+ for named_requirement in needed_inputs.named_input_requirements:
+ new_inputs[named_requirement.variable_name] = named_requirement.concept.code
+ # Update the pipe spec inputs
+ pipe_spec.inputs = new_inputs
+ fixed_pipes.append(pipe_spec)
+
+ if fixed_pipes:
+ pipelex_bundle_spec = await reconstruct_bundle_with_pipe_fixes(pipelex_bundle_spec=pipelex_bundle_spec, fixed_pipes=fixed_pipes)
+ pretty_print(pipelex_bundle_spec, title="Pipelex Bundle Spec • 2nd iteration")
+ plx_content = PlxFactory.make_plx_content(blueprint=pipelex_bundle_spec.to_blueprint())
+ save_text_to_path(text=plx_content, path="results/generated_pipeline_2nd_iteration.plx")
+
+ return pipelex_bundle_spec
diff --git a/pipelex/libraries/pipelines/builder/concept/concept.plx b/pipelex/libraries/pipelines/builder/concept/concept.plx
index aa81136bd..3b9e31db7 100644
--- a/pipelex/libraries/pipelines/builder/concept/concept.plx
+++ b/pipelex/libraries/pipelines/builder/concept/concept.plx
@@ -8,7 +8,7 @@ ConceptSpecDraft = "A specification for a concept including its code, descriptio
[pipe.build_concept_spec]
type = "PipeSequence"
-description = "Create a ConceptSpec from a brief, existing concepts, and concept rules."
+definition = "Create a ConceptSpec from a brief, existing concepts, and concept rules."
inputs = { concept_spec_draft = "ConceptSpecDraft"}
output = "ConceptSpec"
steps = [
@@ -18,7 +18,7 @@ steps = [
[pipe.spec_draft_to_structure]
type = "PipeLLM"
-description = "Convert the ConceptSpec (with its structure draft) into a proper ConceptStructureSpec."
+definition = "Convert the ConceptSpec (with its structure draft) into a proper ConceptStructureSpec."
inputs = { concept_spec_draft = "ConceptSpecDraft" }
output = "ConceptStructureSpec"
multiple_output = true
@@ -36,8 +36,7 @@ ConceptSpecDraft:
[pipe.spec_draft_to_concept_spec]
type = "PipeFunc"
-description = "Generate the final ConceptSpec using the spec and structure manually."
+definition = "Generate the final ConceptSpec using the spec and structure manually."
inputs = { concept_spec_draft = "ConceptSpecDraft", concept_spec_structures = "ConceptStructureSpec"}
output = "ConceptSpec"
function_name = "create_concept_spec"
-
diff --git a/pipelex/libraries/pipelines/builder/concept/concept_spec.py b/pipelex/libraries/pipelines/builder/concept/concept_spec.py
index 7e0751fc9..a5d3a50b5 100644
--- a/pipelex/libraries/pipelines/builder/concept/concept_spec.py
+++ b/pipelex/libraries/pipelines/builder/concept/concept_spec.py
@@ -1,8 +1,9 @@
from datetime import datetime
-from typing import Any, cast
+from typing import Any
from pydantic import ConfigDict, Field, field_validator, model_validator
+from pipelex import log
from pipelex.core.concepts.concept_blueprint import (
ConceptBlueprint,
ConceptBlueprintError,
@@ -10,13 +11,12 @@ from pipelex.core.concepts.concept_blueprint import (
ConceptStructureBlueprintError,
ConceptStructureBlueprintFieldType,
)
-from pipelex.core.concepts.concept_native import NativeConceptEnum, NativeConceptManager
-from pipelex.core.concepts.exceptions import ConceptCodeError, ConceptStringError, ConceptStringOrConceptCodeError
-from pipelex.core.domains.domain import SpecialDomain
+from pipelex.core.concepts.concept_native import NativeConceptManager
+from pipelex.core.concepts.exceptions import ConceptCodeError, ConceptStringOrConceptCodeError
from pipelex.core.domains.domain_blueprint import DomainBlueprint
from pipelex.core.memory.working_memory import WorkingMemory
from pipelex.core.stuffs.stuff_content import StructuredContent
-from pipelex.tools.misc.string_utils import is_pascal_case
+from pipelex.tools.misc.string_utils import is_pascal_case, snake_to_pascal_case
from pipelex.types import Self, StrEnum
@@ -33,11 +33,8 @@ class ConceptSpecError(Exception):
class ConceptStructureSpec(StructuredContent):
- """Spec defining a field in the structure of a concept, used as a Pydantic V2 model.
-
- This class represents the schema for a single field in a concept's structure. It supports
- various field types including text, list, dict, integer, boolean, number, and date, as well
- as choice-based fields (enums).
+ """ConceptStructureSpec represents the schema for a single field in a concept's structure. It supports
+ various field types including text, integer, boolean, number, and date.
Attributes:
the_field_name: Field name. Must be snake_case.
@@ -58,15 +55,20 @@ class ConceptStructureSpec(StructuredContent):
the_field_name: str = Field(description="Field name. Must be snake_case.")
definition: str
- type: ConceptStructureSpecFieldType | None = Field(default=None, description="The type of the field.")
- required: bool | None = True
+ type: ConceptStructureSpecFieldType = Field(description="The type of the field.")
+ required: bool | None = None
default_value: Any | None = None
+ @field_validator("type", mode="before")
+ @classmethod
+ def validate_type(cls, type_value: str) -> ConceptStructureSpecFieldType:
+ return ConceptStructureSpecFieldType(type_value)
+
@model_validator(mode="after")
def validate_structure_blueprint(self) -> Self:
"""Validate the structure blueprint according to type rules."""
# Check default_value type is the same as type
- if self.default_value is not None and self.type is not None:
+ if self.default_value is not None:
self._validate_default_value_type()
return self
@@ -76,8 +78,6 @@ class ConceptStructureSpec(StructuredContent):
return
match self.type:
- case None:
- return
case ConceptStructureSpecFieldType.TEXT:
if not isinstance(self.default_value, str):
self._raise_type_mismatch_error("str", type(self.default_value).__name__)
@@ -101,10 +101,8 @@ class ConceptStructureSpec(StructuredContent):
def to_blueprint(self) -> ConceptStructureBlueprint:
# Convert the type enum value - self.type is already a ConceptStructureBlueprintFieldType enum
# We need to get the corresponding value in the core enum
- core_type = None
- if self.type is not None:
- # Get the string value and use it to get the core enum value
- core_type = ConceptStructureBlueprintFieldType(self.type)
+ # Get the string value and use it to get the core enum value
+ core_type = ConceptStructureBlueprintFieldType(self.type)
return ConceptStructureBlueprint(
definition=self.definition,
@@ -118,7 +116,7 @@ class ConceptSpecDraft(StructuredContent):
the_concept_code: str = Field(description="Concept code. Must be PascalCase.")
definition: str = Field(description="Description of the concept, in natural language.")
structure: str = Field(
- description="A description of a dict with fieldnames as keys, and values being a dict with: definition, type, required, default_value",
+ description="Description of a dict with fieldnames as keys, and values being a dict with: definition, type, required, default_value",
)
refines: str | None = Field(
default=None,
@@ -128,22 +126,7 @@ class ConceptSpecDraft(StructuredContent):
class ConceptSpec(StructuredContent):
- """Spec defining a concept that can be used in the Pipelex framework.
-
- A concept represents a structured data type that can either define its own structure
- or refine an existing native concept. Concepts are fundamental building blocks in
- Pipelex workflows for data validation and transformation.
-
- Attributes:
- the_concept_code: Concept code. Must be PascalCase.
- definition: Natural language description of what the concept represents and its purpose.
- structure: The concept's field structure. Can be either:
- - A string referring to another concept
- - A dictionary where keys are field names (in snake_case) and values are
- either strings (concept references) or ConceptStructureBlueprint instances
- Cannot be used together with 'refines'.
- refines: The native concept this concept extends (Text, Image, PDF, TextAndImages,
- Number, Page) in PascalCase format. Cannot be used together with 'structure'.
+ """Spec structuring a concept: a conceptual data type that can either define its own structure or refine an existing native concept.
Validation Rules:
1. Mutual exclusivity: A concept must have either 'structure' or 'refines', but not both.
@@ -153,79 +136,44 @@ class ConceptSpec(StructuredContent):
4. Concept strings: Format is "domain.ConceptCode" where domain is lowercase and
ConceptCode is PascalCase.
5. Native concepts: When refining, must be one of the valid native concepts.
- 6. Structure values: In structure dict, values must be either valid concept strings
+ 6. Structure values: In structure attribute, values must be either valid concept strings
or ConceptStructureBlueprint instances.
-
"""
model_config = ConfigDict(extra="forbid")
- the_concept_code: str = Field(description="Concept code. Must be PascalCase.")
- definition: str
- structure: str | dict[str, str | ConceptStructureSpec] | None = None
- refines: str | None = None
-
- @classmethod
- def is_native_concept_code(cls, concept_code: str) -> bool:
- ConceptSpec.validate_concept_code(concept_code=concept_code)
- return concept_code in NativeConceptEnum.values_list()
-
- @classmethod
- def validate_concept_code(cls, concept_code: str) -> None:
- if not is_pascal_case(concept_code):
- msg = f"Concept code '{concept_code}' must be PascalCase (letters and numbers only, starting with uppercase, without `.`)"
- raise ConceptCodeError(msg)
+ the_concept_code: str = Field(description="Name of the concept. Must be PascalCase.")
+ definition: str = Field(description="Description of the concept, in natural language.")
+ structure: dict[str, ConceptStructureSpec] | None = Field(
+ default=None,
+ description=(
+ "Definition of the concept's structure. Each attribute (snake_case) specifies: definition, type, and required or default_value if needed"
+ ),
+ )
+ refines: str | None = Field(
+ default=None,
+ description=(
+ "If applicable: the native concept this concept extends (Text, Image, PDF, TextAndImages, Number, Page) "
+ "in PascalCase format. Cannot be used together with 'structure'."
+ ),
+ )
+ @field_validator("the_concept_code", mode="before")
@classmethod
- def validate_concept_string_or_code(cls, concept_string_or_code: str) -> None:
- if concept_string_or_code.count(".") > 1:
- msg = (
- f"concept_string_or_code '{concept_string_or_code}' is invalid. "
- "It should either contain a domain in snake_case and a concept code in PascalCase separated by one dot, "
- "or be a concept code in PascalCase."
- )
- raise ConceptStringOrConceptCodeError(msg)
-
- if concept_string_or_code.count(".") == 1:
- domain, concept_code = concept_string_or_code.split(".")
- DomainBlueprint.validate_domain_code(code=domain)
- cls.validate_concept_code(concept_code=concept_code)
+ def validate_concept_code(cls, value: str) -> str:
+ if "." in value:
+ domain, concept_code = value.split(".")
+ if not is_pascal_case(concept_code):
+ log.warning(f"Concept code '{value}' is not PascalCase, converting to PascalCase")
+ pascal_cased_value = snake_to_pascal_case(concept_code)
+ return f"{domain}.{pascal_cased_value}"
+ else:
+ return value
+ elif not is_pascal_case(value):
+ log.warning(f"Concept code '{value}' is not PascalCase, converting to PascalCase")
+ return snake_to_pascal_case(value)
else:
- cls.validate_concept_code(concept_code=concept_string_or_code)
-
- @staticmethod
- def validate_concept_string(concept_string: str) -> None:
- """Validate that a concept code follows PascalCase convention."""
- if "." not in concept_string or concept_string.count(".") > 1:
- msg = (
- f"Concept string '{concept_string}' is invalid. It should contain a domain in snake_case "
- "and a concept code in PascalCase separated by one dot."
- )
- raise ConceptStringError(msg)
- domain, concept_code = concept_string.split(".", 1)
-
- DomainBlueprint.validate_domain_code(domain)
- if not is_pascal_case(concept_code):
- msg = f"Concept code '{concept_code}' must be PascalCase (letters and numbers only, starting with uppercase, without `.`)"
- raise ConceptCodeError(msg)
-
- # Validate that if the concept code is among the native concepts, the domain MUST be native.
- if not SpecialDomain.is_native(domain=domain) and concept_code in NativeConceptEnum.values_list():
- msg = (
- f"Concept string '{concept_string}' is invalid. "
- f"Concept code '{concept_code}' is a native concept, so the domain must be '{SpecialDomain.NATIVE}', "
- f"or nothing, but not '{domain}'"
- )
- raise ConceptStringError(msg)
-
- # Validate that if the domain is native, the concept code is a native concept
- if SpecialDomain.is_native(domain=domain):
- if concept_code not in NativeConceptEnum.values_list():
- msg = (
- f"Concept string '{concept_string}' is invalid. "
- f"Concept code '{concept_code}' is not a native concept, so the domain must not be '{SpecialDomain.NATIVE}'."
- )
- raise ConceptStringError(msg)
+ return value
@field_validator("refines", mode="before")
@classmethod
@@ -248,17 +196,40 @@ class ConceptSpec(StructuredContent):
raise ConceptSpecError(msg)
return values
+ @classmethod
+ def _post_validate_concept_code(cls, concept_code: str) -> None:
+ if not is_pascal_case(concept_code):
+ msg = (
+ f"ConceptSpec _post_validate_concept_code: Concept code '{concept_code}' must be PascalCase "
+ f"(letters and numbers only, starting with uppercase, without `.`)"
+ )
+ raise ConceptCodeError(msg)
+
+ @classmethod
+ def validate_concept_string_or_code(cls, concept_string_or_code: str) -> None:
+ if concept_string_or_code.count(".") > 1:
+ msg = (
+ f"concept_string_or_code '{concept_string_or_code}' is invalid. "
+ "It should either contain a domain in snake_case and a concept code in PascalCase separated by one dot, "
+ "or be a concept code in PascalCase."
+ )
+ raise ConceptStringOrConceptCodeError(msg)
+
+ if concept_string_or_code.count(".") == 1:
+ domain, concept_code = concept_string_or_code.split(".")
+ DomainBlueprint.validate_domain_code(code=domain)
+ cls._post_validate_concept_code(concept_code=concept_code)
+ else:
+ cls._post_validate_concept_code(concept_code=concept_string_or_code)
+
def to_blueprint(self) -> ConceptBlueprint:
"""Convert this ConceptBlueprint to the original core ConceptBlueprint."""
# TODO: Clarify concept structure blueprint
converted_structure: str | dict[str, str | ConceptStructureBlueprint] | None = None
if self.structure:
converted_structure = {}
- if isinstance(self.structure, str):
- converted_structure = self.structure
- else:
- for field_name, field_spec in cast("dict[str, ConceptStructureSpec]", self.structure).items():
- converted_structure[field_name] = field_spec.to_blueprint()
+ for field_name, field_spec in self.structure.items():
+ converted_structure[field_name] = field_spec.to_blueprint()
return ConceptBlueprint(definition=self.definition, structure=converted_structure, refines=self.refines)
@@ -267,7 +238,7 @@ async def create_concept_spec(working_memory: WorkingMemory) -> ConceptSpec:
concept_spec_draft = working_memory.get_stuff_as(name="concept_spec_draft", content_type=ConceptSpecDraft)
concept_spec_structures_stuff = working_memory.get_stuff_as_list(name="concept_spec_structures", item_type=ConceptStructureSpec)
- structure_dict: dict[str, str | ConceptStructureSpec] = {}
+ structure_dict: dict[str, ConceptStructureSpec] = {}
for structure_item in concept_spec_structures_stuff.items:
structure_spec = ConceptStructureSpec(
the_field_name=structure_item.the_field_name,
diff --git a/pipelex/libraries/pipelines/builder/pipe/inputs_spec.py b/pipelex/libraries/pipelines/builder/pipe/inputs_spec.py
deleted file mode 100644
index 159ad2d6b..000000000
--- a/pipelex/libraries/pipelines/builder/pipe/inputs_spec.py
+++ /dev/null
@@ -1,39 +0,0 @@
-from pydantic import Field, field_validator
-
-from pipelex.core.concepts.concept_blueprint import ConceptBlueprint
-from pipelex.core.pipes.pipe_input_blueprint import InputRequirementBlueprint
-from pipelex.core.pipes.pipe_run_params import PipeOutputMultiplicity
-from pipelex.core.stuffs.stuff_content import StructuredContent
-
-
-class InputRequirementSpec(StructuredContent):
- """Spec specifying input requirements for a pipe in the Pipelex framework.
-
- Defines the concept type and multiplicity constraints for pipe inputs, ensuring
- proper data validation and flow control in pipeline execution.
-
- Attributes:
- concept: The concept code or concept string for the input. Must be in PascalCase
- format. When using concept strings, format is "domain.ConceptCode" with
- domain in lowercase and ConceptCode in PascalCase.
- multiplicity: Optional constraint on input cardinality (e.g., single, multiple).
- Defines how many instances of the concept the pipe can process.
-
- Validation Rules:
- 1. Concept must be a valid concept code (PascalCase) or concept string (domain.ConceptCode).
- 2. Domain and concept code are separated by a dot when using full concept strings.
- 3. Concept validation is performed using ConceptBlueprint.validate_concept_string_or_code.
-
- """
-
- concept: str = Field(description="Concept code or concept string in PascalCase format")
- multiplicity: PipeOutputMultiplicity | None = None
-
- @field_validator("concept", mode="before")
- @classmethod
- def validate_concept_string(cls, concept_string: str) -> str:
- ConceptBlueprint.validate_concept_string_or_code(concept_string_or_code=concept_string)
- return concept_string
-
- def to_blueprint(self) -> InputRequirementBlueprint:
- return InputRequirementBlueprint(concept=self.concept, multiplicity=self.multiplicity)
diff --git a/pipelex/libraries/pipelines/builder/pipe/pipe.plx b/pipelex/libraries/pipelines/builder/pipe/pipe.plx
deleted file mode 100644
index 8de8d6971..000000000
--- a/pipelex/libraries/pipelines/builder/pipe/pipe.plx
+++ /dev/null
@@ -1,480 +0,0 @@
-domain = "pipe"
-definition = "Build and process pipes."
-
-[concept]
-PipeSignature = "Pseudo-Pipelex step: code, type, description, inputs, output, optional children refs."
-PipeSpec = "A structured spec for a pipe (union)."
-# Pipe controllers
-PipeBatchSpec = "A structured spec for a pipe batch."
-PipeConditionSpec = "A structured spec for a pipe condition."
-PipeParallelSpec = "A structured spec for a pipe parallel."
-PipeSequenceSpec = "A structured spec for a pipe sequence."
-# Pipe operators
-PipeFuncSpec = "A structured spec for a pipe func."
-PipeImgGenSpec = "A structured spec for a pipe img gen."
-PipeComposeSpec = "A structured spec for a pipe compose."
-PipeLLMSpec = "A structured spec for a pipe llm."
-PipeOcrSpec = "A structured spec for a pipe ocr."
-PipeFailure = "Details of a single pipe failure during dry run."
-
-[pipe]
-# ────────────────────────────────────────────────────────────────────────────────
-# NEW ENTRY POINT — takes PipeSignature[] + ConceptSpecs → PipeSpecs[]
-# ────────────────────────────────────────────────────────────────────────────────
-[pipe.create_pipes_from_signatures]
-type = "PipeSequence"
-description = "PipeSignature[] + ConceptSpecs → PipeSpecs[] (linked & ready)."
-inputs = { pipe_signature = "PipeSignature", concept_specs = "concept.ConceptSpec" }
-output = "Dynamic"
-steps = [
- { pipe = "generate_pipe_spec", result = "pipe_spec" },
- { pipe = "compile_one_signature_spec", result = "compiled_spec" },
-]
-
-[pipe.generate_pipe_spec]
-type = "PipeLLM"
-description = "Generate a PipeSpec from a PipeSignature."
-inputs = { pipe_signature = "PipeSignature", concept_specs = "concept.ConceptSpec" }
-output = "PipeSpec"
-llm = "llm_to_engineer"
-prompt_template = """
-Return a PipeSpec for this signature.
-
-Signature:
-@pipe_signature
-
-and here are the existing concepts:
-@concept_specs
-
-The inputs keys should be snake_case.
-The values should be a concept code in PascalCase.
-"""
-
-# ────────────────────────────────────────────────────────────────────────────────
-# CORE: signature → route to spec emitter
-# ────────────────────────────────────────────────────────────────────────────────
-[pipe.compile_one_signature_spec]
-type = "PipeCondition"
-description = "Route by signature.type to the correct spec emitter."
-inputs = { pipe_signature = "PipeSignature", concept_specs = "ConceptSpec", pipe_spec = "PipeSpec" }
-output = "Dynamic"
-expression = "pipe_signature.type"
-
-[pipe.compile_one_signature_spec.pipe_map]
-PipeSequence = "emit_sequence_from_signature"
-PipeParallel = "emit_parallel_from_signature"
-PipeCondition = "emit_condition_from_signature"
-PipeBatch = "emit_batch_from_signature"
-PipeLLM = "emit_llm_from_signature"
-PipeOcr = "emit_ocr_from_signature"
-PipeImgGen = "emit_imggen_from_signature"
-PipeCompose = "emit_compose_from_signature"
-PipeFunc = "emit_func_from_signature"
-
-# ────────────────────────────────────────────────────────────────────────────────
-# EMITTERS — one per pipe type, all using the same minimal contract
-# (Optionally, emitters could be extended later to read from concept_index.)
-# ────────────────────────────────────────────────────────────────────────────────
-
-[pipe.emit_sequence_from_signature]
-type = "PipeLLM"
-description = "Build a PipeSequenceSpec from the signature (children referenced by code)."
-inputs = { pipe_signature = "PipeSignature", concept_specs = "concept.ConceptSpec", pipe_spec = "PipeSpec" }
-output = "PipeSequenceSpec"
-llm = "llm_to_engineer"
-prompt_template = """
-Return a PipeSequenceSpec for this signature.
-The Pipe sequence NEEDS to have at least one step.
-Orchestrate all the necessary steps to achieve the goal of the pipe.
-
-Signature:
-@pipe_signature
-
-Here is the base PipeSpec:
-@pipe_spec
-
-And here are the concepts you can use:
-@concept_specs
-"""
-
-[pipe.emit_parallel_from_signature]
-type = "PipeLLM"
-description = "Build a PipeParallelSpec from the signature."
-inputs = { pipe_signature = "PipeSignature", concept_specs = "concept.ConceptSpec", pipe_spec = "PipeSpec" }
-output = "PipeParallelSpec"
-llm = "llm_to_engineer"
-prompt_template = """
-Return a PipeParallelSpec for this signature.
-
-Signature:
-@pipe_signature
-
-Here is the base PipeSpec:
-@pipe_spec
-
-And here are the concepts you can use:
-@concept_specs
-"""
-
-[pipe.emit_condition_from_signature]
-type = "PipeLLM"
-description = "Build a PipeConditionSpec from the signature (provide expression/pipe_map consistent with children)."
-inputs = { pipe_signature = "PipeSignature", concept_specs = "concept.ConceptSpec", pipe_spec = "PipeSpec" }
-output = "PipeConditionSpec"
-llm = "llm_to_engineer"
-prompt_template = """
-Return a PipeConditionSpec for this signature.
-
-Signature:
-@pipe_signature
-
-Here is the base PipeSpec:
-@pipe_spec
-
-And here are the concepts you can use:
-@concept_specs
-"""
-
-[pipe.emit_batch_from_signature]
-type = "PipeLLM"
-description = "Build a PipeBatchSpec from the signature (choose branch_pipe_code/params)."
-inputs = { pipe_signature = "PipeSignature", concept_specs = "concept.ConceptSpec", pipe_spec = "PipeSpec" }
-output = "PipeBatchSpec"
-llm = "llm_to_engineer"
-prompt_template = """
-Return a PipeBatchSpec for this signature.
-
-Signature:
-@pipe_signature
-
-Here is the base PipeSpec:
-@pipe_spec
-
-And here are the concepts you can use:
-@concept_specs
-"""
-
-[pipe.emit_llm_from_signature]
-type = "PipeLLM"
-description = "Build a PipeLLMSpec from the signature."
-inputs = { pipe_signature = "PipeSignature", concept_specs = "concept.ConceptSpec", pipe_spec = "PipeSpec" }
-output = "PipeLLMSpec"
-llm = "llm_to_engineer"
-prompt_template = """
-Return a PipeLLMSpec for this signature.
-
-THe prompt is the field "prompt_template" in the PipeLLMSpec.
-Signature:
-@pipe_signature
-
-Here is the base PipeSpec:
-@pipe_spec
-
-And here are the concepts you can use:
-@concept_specs
-"""
-
-[pipe.emit_ocr_from_signature]
-type = "PipeLLM"
-description = "Build a PipeOcrSpec from the signature."
-inputs = { pipe_signature = "PipeSignature", concept_specs = "concept.ConceptSpec", pipe_spec = "PipeSpec" }
-output = "PipeOcrSpec"
-prompt_template = """
-Return a PipeOcrSpec for this signature.
-
-VERY IMPORTANT: THE INPUT OF THE PIPEOCR MUST BE either an image or a pdf or a concept which refines one of them.
-Signature:
-@pipe_signature
-
-Here is the base PipeSpec:
-@pipe_spec
-
-And here are the concepts you can use:
-@concept_specs
-"""
-
-[pipe.emit_imggen_from_signature]
-type = "PipeLLM"
-description = "Build a PipeImgGenSpec from the signature."
-inputs = { pipe_signature = "PipeSignature", concept_specs = "concept.ConceptSpec", pipe_spec = "PipeSpec" }
-output = "PipeImgGenSpec"
-prompt_template = """
-Return a PipeImgGenSpec for this signature.
-The inputs for the image has to be only:
-input_name : prompt
-concept : A concept that refines Text. It should be text
-The output concept should be a concept in Pascal case that refines Image.
-For example:
-```
-inputs = { prompt: ImgGenPrompt }
-```
-if ImgGenPrompt is a text concept.
-
-IMPORTANT: imgg_prompt SHOULD BE NONE
-IMPORTANT: img_gen_prompt_var_name SHOULD BE NONE
-The prompt will need to be be generated by a pipe with the necessary elements.
-
-Signature:
-@pipe_signature
-
-Here is the base PipeSpec:
-@pipe_spec
-
-And here are the concepts you can use:
-@concept_specs
-"""
-
-[pipe.emit_compose_from_signature]
-type = "PipeLLM"
-description = "Build a PipeComposeSpec from the signature."
-inputs = { pipe_signature = "PipeSignature", concept_specs = "concept.ConceptSpec", pipe_spec = "PipeSpec" }
-output = "PipeComposeSpec"
-prompt_template = """
-Return a PipeComposeSpec for this signature.
-
-Signature:
-@pipe_signature
-
-Here is the base PipeSpec:
-@pipe_spec
-
-And here are the concepts you can use:
-@concept_specs
-"""
-
-[pipe.emit_func_from_signature]
-type = "PipeLLM"
-description = "Build a PipeFuncSpec from the signature."
-inputs = { pipe_signature = "PipeSignature", concept_specs = "concept.ConceptSpec", pipe_spec = "PipeSpec" }
-output = "PipeFuncSpec"
-llm = "llm_to_engineer"
-prompt_template = """
-Return a PipeFuncSpec for this signature.
-
-Signature:
-@pipe_signature
-
-Here is the base PipeSpec:
-@pipe_spec
-
-And here are the concepts you can use:
-@concept_specs
-"""
-
-# ────────────────────────────────────────────────────────────────────────────────
-# 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_compose_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)
-- Wrong img_gen_prompt_var_name (should be None or "prompt")
-- Invalid img_gen choice
-- 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_compose_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 compose 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/libraries/pipelines/builder/pipe/pipe_batch_spec.py b/pipelex/libraries/pipelines/builder/pipe/pipe_batch_spec.py
index 46741432b..9d1adf5fb 100644
--- a/pipelex/libraries/pipelines/builder/pipe/pipe_batch_spec.py
+++ b/pipelex/libraries/pipelines/builder/pipe/pipe_batch_spec.py
@@ -18,16 +18,6 @@ class PipeBatchSpec(PipeSpec):
where the batch configuration is specified directly in the sequence step using
batch_over and batch_as parameters in SubPipeBlueprint.
- Attributes:
- the_pipe_code: Pipe code. Must be snake_case.
- type: Fixed to "PipeBatch" for this pipe type.
- branch_pipe_code: The pipe code to execute for each item in the input list.
- This pipe is instantiated once per item in parallel.
- input_list_name: Name of the list in WorkingMemory to iterate over.
- Defaults to the PipeBatch's main input name if not specified.
- input_item_name: Name assigned to individual items within each execution branch.
- This is how the branch pipe accesses its specific input item.
-
Validation Rules:
1. branch_pipe_code must reference an existing pipe in the pipeline.
2. When input_list_name is specified, it must reference a list in context.
@@ -38,9 +28,14 @@ class PipeBatchSpec(PipeSpec):
type: Literal["PipeBatch"] = "PipeBatch"
category: Literal["PipeController"] = "PipeController"
the_pipe_code: str = Field(description="Pipe code. Must be snake_case.")
- branch_pipe_code: str
- input_list_name: str | None = None
- input_item_name: str | None = None
+ branch_pipe_code: str = Field(
+ description="The pipe code to execute for each item in the input list. This pipe is instantiated once per item in parallel."
+ )
+ input_list_name: str | None = Field(default=None, description="Name of the list in WorkingMemory to iterate over, if needed.")
+ input_item_name: str | None = Field(
+ default=None,
+ description="Name assigned to individual items within each execution branch. This is how the branch pipe accesses its specific input item.",
+ )
@override
def to_blueprint(self) -> PipeBatchBlueprint:
diff --git a/pipelex/libraries/pipelines/builder/pipe/pipe_compose_spec.py b/pipelex/libraries/pipelines/builder/pipe/pipe_compose_spec.py
index 7555c7457..650690d42 100644
--- a/pipelex/libraries/pipelines/builder/pipe/pipe_compose_spec.py
+++ b/pipelex/libraries/pipelines/builder/pipe/pipe_compose_spec.py
@@ -1,45 +1,98 @@
-from typing import Any, Literal
+from typing import Literal
-from pydantic import Field
+from pydantic import Field, field_validator
+from pydantic.json_schema import SkipJsonSchema
from typing_extensions import override
-from pipelex.core.stuffs.stuff_content import StructuredContent
from pipelex.libraries.pipelines.builder.pipe.pipe_signature import PipeSpec
from pipelex.pipe_operators.compose.pipe_compose_blueprint import PipeComposeBlueprint
from pipelex.tools.templating.jinja2_template_category import Jinja2TemplateCategory
from pipelex.tools.templating.templating_models import PromptingStyle, TagStyle, TextFormat
+from pipelex.types import StrEnum
-class PromptingStyleSpec(StructuredContent):
- tag_style: TagStyle = Field(strict=False)
- text_format: TextFormat = Field(TextFormat.PLAIN, strict=False)
+class TargetFormat(StrEnum):
+ PLAIN = "plain"
+ MARKDOWN = "markdown"
+ HTML = "html"
+ JSON = "json"
+ SPREADSHEET = "spreadsheet"
+ MERMAID = "mermaid"
+
+ @property
+ def tag_style(self) -> TagStyle:
+ match self:
+ case TargetFormat.PLAIN:
+ return TagStyle.NO_TAG
+ case TargetFormat.MARKDOWN:
+ return TagStyle.TICKS
+ case TargetFormat.HTML:
+ return TagStyle.XML
+ case TargetFormat.JSON:
+ return TagStyle.SQUARE_BRACKETS
+ case TargetFormat.SPREADSHEET:
+ return TagStyle.NO_TAG
+ case TargetFormat.MERMAID:
+ return TagStyle.NO_TAG
+
+ @property
+ def text_format(self) -> TextFormat:
+ match self:
+ case TargetFormat.PLAIN:
+ return TextFormat.PLAIN
+ case TargetFormat.MARKDOWN:
+ return TextFormat.MARKDOWN
+ case TargetFormat.HTML:
+ return TextFormat.HTML
+ case TargetFormat.JSON:
+ return TextFormat.JSON
+ case TargetFormat.SPREADSHEET:
+ return TextFormat.SPREADSHEET
+ case TargetFormat.MERMAID:
+ return TextFormat.PLAIN
+
+ @property
+ def prompting_style(self) -> PromptingStyle:
+ return PromptingStyle(tag_style=self.tag_style, text_format=self.text_format)
+
+ @property
+ def template_category(self) -> Jinja2TemplateCategory:
+ match self:
+ case TargetFormat.PLAIN:
+ return Jinja2TemplateCategory.MARKDOWN
+ case TargetFormat.MARKDOWN:
+ return Jinja2TemplateCategory.MARKDOWN
+ case TargetFormat.HTML:
+ return Jinja2TemplateCategory.HTML
+ case TargetFormat.JSON:
+ return Jinja2TemplateCategory.HTML
+ case TargetFormat.SPREADSHEET:
+ return Jinja2TemplateCategory.HTML
+ case TargetFormat.MERMAID:
+ return Jinja2TemplateCategory.MERMAID
class PipeComposeSpec(PipeSpec):
- type: Literal["PipeCompose"] = "PipeCompose"
- category: Literal["PipeOperator"] = "PipeOperator"
+ """PipeComposeSpec defines a templating operation based on a Jinja2 template."""
+
+ type: SkipJsonSchema[Literal["PipeCompose"]] = "PipeCompose"
+ category: SkipJsonSchema[Literal["PipeOperator"]] = "PipeOperator"
the_pipe_code: str = Field(description="Pipe code. Must be snake_case.")
- jinja2_name: str | None = Field(default=None, description="Name of the Jinja2 template to use")
- jinja2: str | None = Field(default=None, description="Raw Jinja2 template string")
- prompting_style: PromptingStyleSpec | None = Field(default=None, description="Style of prompting to use (typically for different LLMs)")
- template_category: Jinja2TemplateCategory = Field(
- default=Jinja2TemplateCategory.LLM_PROMPT,
- description="Category of the template (could also be HTML, MARKDOWN, MERMAID, etc.), influences Jinja2 rendering environment config",
- )
- extra_context: dict[str, Any] | None = Field(default=None, description="Additional context variables for template rendering")
+ jinja2: str | None = Field(default=None, description="Jinja2 template string")
+ target_format: TargetFormat | str = Field(description="Target format for the output")
+
+ @field_validator("target_format", mode="before")
+ @classmethod
+ def validate_target_format(cls, target_format_value: str) -> TargetFormat:
+ return TargetFormat(target_format_value)
@override
def to_blueprint(self) -> PipeComposeBlueprint:
base_blueprint = super().to_blueprint()
- if self.prompting_style:
- prompting_style = (
- self.prompting_style
- if isinstance(self.prompting_style, PromptingStyle)
- else PromptingStyle(tag_style=self.prompting_style.tag_style, text_format=self.prompting_style.text_format)
- )
- else:
- prompting_style = None
+ target_format = TargetFormat(self.target_format)
+ prompting_style = target_format.prompting_style
+ template_category = target_format.template_category
return PipeComposeBlueprint(
definition=base_blueprint.definition,
@@ -47,9 +100,9 @@ class PipeComposeSpec(PipeSpec):
output=base_blueprint.output,
type=self.type,
category=self.category,
- jinja2_name=self.jinja2_name,
+ jinja2_name=None,
jinja2=self.jinja2,
prompting_style=prompting_style,
- template_category=self.template_category,
- extra_context=self.extra_context,
+ template_category=template_category,
+ extra_context=None,
)
diff --git a/pipelex/libraries/pipelines/builder/pipe/pipe_condition_spec.py b/pipelex/libraries/pipelines/builder/pipe/pipe_condition_spec.py
index 65d745fba..7fed2b91f 100644
--- a/pipelex/libraries/pipelines/builder/pipe/pipe_condition_spec.py
+++ b/pipelex/libraries/pipelines/builder/pipe/pipe_condition_spec.py
@@ -1,49 +1,16 @@
from typing import Literal
-from pydantic import Field, RootModel
+from pydantic import Field
+from pydantic.json_schema import SkipJsonSchema
from typing_extensions import override
from pipelex.libraries.pipelines.builder.pipe.pipe_signature import PipeSpec
from pipelex.pipe_controllers.condition.pipe_condition_blueprint import PipeConditionBlueprint, PipeConditionPipeMapBlueprint
-PipeConditionPipeMapRoot = dict[str, str]
-
-
-class PipeConditionPipeMapSpec(RootModel[PipeConditionPipeMapRoot]):
- """Spec for condition-to-pipe mapping in PipeCondition.
-
- Maps condition values to pipe codes for conditional execution.
-
- Attributes:
- root: Dictionary mapping condition results (keys) to pipe codes (values).
- Each key represents a possible condition outcome, and its value
- is the pipe code to execute when that condition is met.
-
- """
-
- root: PipeConditionPipeMapRoot = Field(default_factory=dict)
-
class PipeConditionSpec(PipeSpec):
- """Spec for conditional pipe execution in the Pipelex framework.
-
- PipeCondition enables branching logic in pipelines by evaluating expressions
- and executing different pipes based on the results. Supports template-based
- and direct expression evaluation with default fallback options.
-
- Attributes:
- the_pipe_code: Pipe code. Must be snake_case.
- type: Fixed to "PipeCondition" for this pipe type.
- expression_template: Template for building the expression to evaluate.
- Supports variable substitution for dynamic conditions.
- expression: Direct expression to evaluate. Typically uses the result
- of the previous pipe. Mutually exclusive with expression_template.
- pipe_map: Mapping of condition results to pipe codes. Each condition
- outcome triggers execution of its associated pipe.
- default_pipe_code: Fallback pipe to execute when no conditions in pipe_map
- match the expression result.
- add_alias_from_expression_to: Optional name to store the expression result
- in the context for later reference.
+ """PipeConditionSpec enables branching logic in pipelines by evaluating expressions
+ and executing different pipes based on the results.
Validation Rules:
1. Either expression or expression_template should be provided, not both.
@@ -52,28 +19,28 @@ class PipeConditionSpec(PipeSpec):
"""
- type: Literal["PipeCondition"] = "PipeCondition"
- category: Literal["PipeController"] = "PipeController"
+ type: SkipJsonSchema[Literal["PipeCondition"]] = "PipeCondition"
+ category: SkipJsonSchema[Literal["PipeController"]] = "PipeController"
the_pipe_code: str = Field(description="Pipe code. Must be snake_case.")
- expression_template: str | None = None
- expression: str | None = None
- pipe_map: PipeConditionPipeMapSpec = Field(default_factory=PipeConditionPipeMapSpec)
- default_pipe_code: str | None = None
- add_alias_from_expression_to: str | None = None
+ jinja2_expression_template: str = Field(description="Jinja2 expression to evaluate.")
+ pipe_map: dict[str, str] = Field(..., description="Mapping `dict[str, str]` of condition results to pipe codes.")
+ default_pipe_code: str | None = Field(
+ default=None, description="The fallback pipe code to execute if the expression result does not match any key in pipe_map."
+ )
@override
def to_blueprint(self) -> PipeConditionBlueprint:
base_blueprint = super().to_blueprint()
- pipe_map_dict = PipeConditionPipeMapBlueprint(root=dict(self.pipe_map.root))
+ pipe_map_blueprint = PipeConditionPipeMapBlueprint(root=dict(self.pipe_map))
return PipeConditionBlueprint(
definition=base_blueprint.definition,
inputs=base_blueprint.inputs,
output=base_blueprint.output,
type=self.type,
category=self.category,
- expression_template=self.expression_template,
- expression=self.expression,
- pipe_map=pipe_map_dict,
+ expression_template=self.jinja2_expression_template,
+ expression=None,
+ pipe_map=pipe_map_blueprint,
default_pipe_code=self.default_pipe_code,
- add_alias_from_expression_to=self.add_alias_from_expression_to,
+ add_alias_from_expression_to=None,
)
diff --git a/pipelex/libraries/pipelines/builder/pipe/pipe_design.plx b/pipelex/libraries/pipelines/builder/pipe/pipe_design.plx
new file mode 100644
index 000000000..23ed345c8
--- /dev/null
+++ b/pipelex/libraries/pipelines/builder/pipe/pipe_design.plx
@@ -0,0 +1,173 @@
+domain = "pipe_design"
+definition = "Build and process pipes."
+
+[concept]
+PipeSignature = "A pipe contract which says what the pipe does, not how it does it: code (the pipe code in snake_case), type, description, inputs, output."
+PipeSpec = "A structured spec for a pipe (union)."
+# Pipe controllers
+PipeBatchSpec = "A structured spec for a pipe batch."
+PipeConditionSpec = "A structured spec for a pipe condition."
+PipeParallelSpec = "A structured spec for a pipe parallel."
+PipeSequenceSpec = "A structured spec for a pipe sequence."
+# Pipe operators
+PipeFuncSpec = "A structured spec for a pipe func."
+PipeImgGenSpec = "A structured spec for a pipe img gen."
+# PipeComposeSpec = "A structured spec for a pipe jinja2."
+PipeLLMSpec = "A structured spec for a pipe llm."
+PipeOcrSpec = "A structured spec for a pipe ocr."
+PipeFailure = "Details of a single pipe failure during dry run."
+
+[pipe]
+
+[pipe.detail_pipe_spec]
+type = "PipeCondition"
+definition = "Route by signature.type to the correct spec emitter."
+inputs = { plan_draft = "PlanDraft", pipe_signature = "PipeSignature", concept_specs = "ConceptSpec" }
+output = "Dynamic"
+expression = "pipe_signature.type"
+default_pipe_code = "continue"
+
+[pipe.detail_pipe_spec.pipe_map]
+PipeSequence = "detail_pipe_sequence"
+PipeParallel = "detail_pipe_parallel"
+PipeCondition = "detail_pipe_condition"
+PipeLLM = "detail_pipe_llm"
+PipeOcr = "detail_pipe_ocr"
+PipeImgGen = "detail_pipe_img_gen"
+
+# ────────────────────────────────────────────────────────────────────────────────
+# PIPE CONTROLLERS
+# ────────────────────────────────────────────────────────────────────────────────
+
+[pipe.detail_pipe_sequence]
+type = "PipeLLM"
+definition = "Build a PipeSequenceSpec from the signature (children referenced by code)."
+inputs = { plan_draft = "PlanDraft", pipe_signature = "PipeSignature", concept_specs = "concept.ConceptSpec" }
+output = "PipeSequenceSpec"
+llm = "llm_to_engineer"
+prompt_template = """
+Your job is to design a PipeSequenceSpec to orchestrate a sequence of pipe steps that will run one after the other.
+
+This PipeSequence is part of a larger pipeline:
+@plan_draft
+
+You will specifically generate the PipeSequence related to this signature:
+@pipe_signature
+"""
+
+[pipe.detail_pipe_parallel]
+type = "PipeLLM"
+definition = "Build a PipeParallelSpec from the signature."
+inputs = { plan_draft = "PlanDraft", pipe_signature = "PipeSignature", concept_specs = "concept.ConceptSpec" }
+output = "PipeParallelSpec"
+llm = "llm_to_engineer"
+prompt_template = """
+Your job is to design a PipeParallelSpec to orchestrate a bunch of pipe steps that will run in parallel.
+
+This PipeParallel is part of a larger pipeline:
+@plan_draft
+
+You will specifically generate the PipeParallel related to this signature:
+@pipe_signature
+"""
+
+[pipe.detail_pipe_condition]
+type = "PipeLLM"
+definition = "Build a PipeConditionSpec from the signature (provide expression/pipe_map consistent with children)."
+inputs = { plan_draft = "PlanDraft", pipe_signature = "PipeSignature", concept_specs = "concept.ConceptSpec" }
+output = "PipeConditionSpec"
+llm = "llm_to_engineer"
+prompt_template = """
+Your job is to design a PipeConditionSpec to route to the correct pipe step based on a conditional expression.
+
+This PipeCondition is part of a larger pipeline:
+@plan_draft
+
+You will specifically generate the PipeCondition related to this signature:
+@pipe_signature
+"""
+
+# ────────────────────────────────────────────────────────────────────────────────
+# PIPE OPERATORS
+# ────────────────────────────────────────────────────────────────────────────────
+
+[pipe.detail_pipe_llm]
+type = "PipeLLM"
+definition = "Build a PipeLLMSpec from the signature."
+inputs = { plan_draft = "PlanDraft", pipe_signature = "PipeSignature", concept_specs = "concept.ConceptSpec" }
+output = "PipeLLMSpec"
+llm = "llm_to_engineer"
+prompt_template = """
+Your job is to design a PipeLLMSpec to use an LLM to generate a text, or a structured object using different kinds of inputs.
+Whatever it's really going to do has already been decided, as you can see:
+
+This PipeLLM is part of a larger pipeline:
+@plan_draft
+
+You will specifically generate the PipeLLM related to this signature:
+@pipe_signature
+
+If it's a structured generation, indicate it in the system_prompt to clarify the task.
+If it's to generate free form text, the prompt_template should indicate to be concise.
+If it's to generate an image generation, the prompt_template should indicate to be VERY concise and focus and apply the best practice for image generation.
+"""
+
+[pipe.detail_pipe_ocr]
+type = "PipeLLM"
+definition = "Build a PipeOcrSpec from the signature."
+inputs = { plan_draft = "PlanDraft", pipe_signature = "PipeSignature", concept_specs = "concept.ConceptSpec" }
+output = "PipeOcrSpec"
+llm = "llm_to_engineer"
+prompt_template = """
+Your job is to design a PipeOcrSpec to extract text from an image or a pdf.
+
+This PipeOcr is part of a larger pipeline:
+@plan_draft
+
+You will specifically generate the PipeOcr related to this signature:
+@pipe_signature
+"""
+
+[pipe.detail_pipe_img_gen]
+type = "PipeLLM"
+definition = "Build a PipeImgGenSpec from the signature."
+inputs = { plan_draft = "PlanDraft", pipe_signature = "PipeSignature", concept_specs = "concept.ConceptSpec" }
+output = "PipeImgGenSpec"
+llm = "llm_to_engineer"
+prompt_template = """
+Your job is to design a PipeImgGenSpec to generate an image from a text prompt.
+
+This PipeImgGen is part of a larger pipeline:
+@plan_draft
+
+You will specifically generate the PipeImgGen related to this signature:
+@pipe_signature
+
+The inputs for the image has to be a single input which must be a Text or another concept which refines Text.
+"""
+
+[pipe.detail_pipe_compose]
+type = "PipeLLM"
+definition = "Build a PipeComposeSpec from the signature."
+inputs = { plan_draft = "PlanDraft", pipe_signature = "PipeSignature", concept_specs = "concept.ConceptSpec" }
+output = "PipeComposeSpec"
+llm = "llm_to_engineer"
+prompt_template = """
+Your job is to design a PipeComposeSpec to render a jinja2 template.
+
+This PipeCompose is part of a larger pipeline:
+@plan_draft
+
+You will specifically generate the PipeCompose related to this signature:
+@pipe_signature
+
+You can ONLY USE THE INPUTS IN THIS PIPE SIGNATURE.
+
+Here are the Jinja2 filters that are supported:
+default — Returns a fallback value if the input is undefined (or falsey if enabled).
+tag - Returns by tagging it with a title.
+format - Apply the given values to a printf-style format string, like string % values.
+length — Returns the number of items (alias: count).
+upper — Converts a string to uppercase.
+lower — Converts a string to lowercase.
+"""
diff --git a/pipelex/libraries/pipelines/builder/pipe/pipe_func_spec.py b/pipelex/libraries/pipelines/builder/pipe/pipe_func_spec.py
index 08e39c20e..92f4b7332 100644
--- a/pipelex/libraries/pipelines/builder/pipe/pipe_func_spec.py
+++ b/pipelex/libraries/pipelines/builder/pipe/pipe_func_spec.py
@@ -1,6 +1,7 @@
from typing import Literal
from pydantic import Field
+from pydantic.json_schema import SkipJsonSchema
from typing_extensions import override
from pipelex.libraries.pipelines.builder.pipe.pipe_signature import PipeSpec
@@ -8,18 +9,10 @@ from pipelex.pipe_operators.func.pipe_func_blueprint import PipeFuncBlueprint
class PipeFuncSpec(PipeSpec):
- """PipeFunc enables calling custom functions in the Pipelex framework.
+ """PipeFunc enables calling custom functions in the Pipelex framework."""
- Attributes:
- the_pipe_code: Pipe code. Must be snake_case.
- type: Fixed to "PipeFunc" for this pipe type.
- category: Fixed to "PipeOperator" for this pipe category.
- function_name: The name of the function to call.
-
- """
-
- type: Literal["PipeFunc"] = "PipeFunc"
- category: Literal["PipeOperator"] = "PipeOperator"
+ type: SkipJsonSchema[Literal["PipeFunc"]] = "PipeFunc"
+ category: SkipJsonSchema[Literal["PipeOperator"]] = "PipeOperator"
the_pipe_code: str = Field(description="Pipe code. Must be snake_case.")
function_name: str = Field(description="The name of the function to call.")
diff --git a/pipelex/libraries/pipelines/builder/pipe/pipe_img_spec.py b/pipelex/libraries/pipelines/builder/pipe/pipe_img_spec.py
index a0c4f83b3..be400c516 100644
--- a/pipelex/libraries/pipelines/builder/pipe/pipe_img_spec.py
+++ b/pipelex/libraries/pipelines/builder/pipe/pipe_img_spec.py
@@ -1,12 +1,17 @@
from typing import Literal
-from pydantic import Field
+from pydantic import Field, field_validator
from typing_extensions import override
-from pipelex.cogt.img_gen.img_gen_job_components import AspectRatio, Background, OutputFormat
-from pipelex.cogt.img_gen.img_gen_setting import ImgGenChoice
from pipelex.libraries.pipelines.builder.pipe.pipe_signature import PipeSpec
from pipelex.pipe_operators.img_gen.pipe_img_gen_blueprint import PipeImgGenBlueprint
+from pipelex.types import StrEnum
+
+
+class RecommendedImgGen(StrEnum):
+ BASE_IMG_GEN = "base_img_gen"
+ FAST_IMG_GEN = "fast_img_gen"
+ HIGH_QUALITY_IMG_GEN = "high_quality_img_gen"
class PipeImgGenSpec(PipeSpec):
@@ -15,54 +20,21 @@ class PipeImgGenSpec(PipeSpec):
PipeImgGen enables AI-powered image generation using various models like DALL-E or
diffusion models. Supports static and dynamic prompts with configurable generation
parameters.
-
- Attributes:
- the_pipe_code: Pipe code. Must be snake_case.
- type: Fixed to "PipeImgGen" for this pipe type.
- img_gen_prompt: Static text prompt for image generation. Use this or dynamic input.
- img_gen: Image generation choice (e.g., 'gpt-image-1'). Defaults to global config.
- aspect_ratio: Desired image aspect ratio (e.g., '16:9', '1:1').
- quality: Generated image quality setting (e.g., 'standard', 'hd').
- nb_steps: Number of diffusion steps for diffusion models. More steps increase detail
- but take longer. Must be > 0.
- guidance_scale: Prompt adherence strength. Higher values mean closer adherence to prompt.
- Must be > 0.
- is_moderated: Whether to apply content moderation to generated images.
- safety_tolerance: Content moderation tolerance level. Must be between 1 and 6.
- is_raw: Whether to return raw image data instead of processed format.
- seed: Random seed for reproducibility. Use integer value or 'auto' for random seed.
- nb_output: Number of images to generate. Defaults to single image. Must be >= 1.
- img_gen_prompt_var_name: Variable name for dynamic prompt generation from inputs. Do not assign anything
-
- Validation Rules:
- 1. Quality and nb_steps are mutually exclusive (cannot specify both).
- 2. nb_steps must be greater than 0 when specified.
- 3. guidance_scale must be greater than 0 when specified.
- 4. safety_tolerance must be between 1 and 6 inclusive.
- 5. nb_output must be at least 1 when specified.
-
- Raises:
- PipeDefinitionError: When validation rules are violated or mutually exclusive
- fields are set simultaneously.
-
"""
type: Literal["PipeImgGen"] = "PipeImgGen"
category: Literal["PipeOperator"] = "PipeOperator"
the_pipe_code: str = Field(description="Pipe code. Must be snake_case.")
- img_gen_prompt: str | None = None
- img_gen_prompt_var_name: str | None = None
-
- # New ImgGenChoice pattern (like LLM)
- img_gen: ImgGenChoice | None = None
-
- # One-time settings (not in ImgGenSetting)
- aspect_ratio: AspectRatio | None = Field(default=None, strict=False)
- is_raw: bool | None = None
- seed: int | Literal["auto"] | None = None
+ img_gen: RecommendedImgGen | None = None
nb_output: int | None = Field(default=None, ge=1)
- background: Background | None = Field(default=None, strict=False)
- output_format: OutputFormat | None = Field(default=None, strict=False)
+
+ @field_validator("img_gen", mode="before")
+ @classmethod
+ def validate_img_gen(cls, img_gen_value: str | None) -> RecommendedImgGen | None:
+ if img_gen_value is None:
+ return None
+ else:
+ return RecommendedImgGen(img_gen_value)
@override
def to_blueprint(self) -> PipeImgGenBlueprint:
@@ -74,13 +46,13 @@ class PipeImgGenSpec(PipeSpec):
output=base_blueprint.output,
type=self.type,
category=self.category,
- img_gen_prompt=self.img_gen_prompt,
+ img_gen_prompt=None,
+ img_gen_prompt_var_name=None,
img_gen=self.img_gen,
- aspect_ratio=self.aspect_ratio,
- background=self.background,
- output_format=self.output_format,
- is_raw=self.is_raw,
- seed=self.seed,
+ aspect_ratio=None,
+ background=None,
+ output_format=None,
+ is_raw=None,
+ seed=None,
nb_output=self.nb_output,
- img_gen_prompt_var_name=None, # Core expects None, builder uses "prompt" as default
)
diff --git a/pipelex/libraries/pipelines/builder/pipe/pipe_llm_spec.py b/pipelex/libraries/pipelines/builder/pipe/pipe_llm_spec.py
index c193f884f..5c6d2fd7b 100644
--- a/pipelex/libraries/pipelines/builder/pipe/pipe_llm_spec.py
+++ b/pipelex/libraries/pipelines/builder/pipe/pipe_llm_spec.py
@@ -1,163 +1,153 @@
-from typing import Literal, Union
+from typing import TYPE_CHECKING, Literal
from pydantic import Field, field_validator, model_validator
+from pydantic.json_schema import SkipJsonSchema
from typing_extensions import override
-from pipelex.cogt.llm.llm_setting import LLMChoice, LLMSetting
-from pipelex.core.stuffs.stuff_content import StructuredContent
+from pipelex.cogt.llm.llm_setting import LLMSetting
from pipelex.exceptions import PipeDefinitionError
from pipelex.libraries.pipelines.builder.pipe.pipe_signature import PipeSpec
-from pipelex.pipe_operators.llm.pipe_llm_blueprint import PipeLLMBlueprint, StructuringMethod
-from pipelex.tools.typing.validation_utils import has_more_than_one_among_attributes_from_lists
-from pipelex.types import Self
-
-
-class LLMSettingSpec(StructuredContent):
- llm_handle: str
- temperature: float = Field(..., ge=0, le=1)
- max_tokens: int | None = None
-
- @field_validator("max_tokens", mode="before")
- @classmethod
- def validate_max_tokens(cls, value: int | Literal["auto"] | None) -> int | None:
- if value is None or (isinstance(value, str) and value == "auto"):
- return None
- if isinstance(value, int): # pyright: ignore[reportUnnecessaryIsInstance]
- return value
-
-
-LLMChoiceSpec = Union[LLMSettingSpec, str]
+from pipelex.pipe_operators.llm.pipe_llm_blueprint import PipeLLMBlueprint
+from pipelex.tools.typing.validation_utils import has_more_than_one_among_attributes_from_list
+from pipelex.types import Self, StrEnum
+
+if TYPE_CHECKING:
+ from pipelex.cogt.llm.llm_setting import LLMChoice
+
+
+class AvailableLLM(StrEnum):
+ CLAUDE_4_SONNET = "claude-4-sonnet"
+ CLAUDE_4_1_OPUS = "claude-4.1-opus"
+ GPT_5 = "gpt-5"
+ GPT_5_MINI = "gpt-5-mini"
+ GEMINI_2_5_PRO = "gemini-2.5-pro"
+ GEMINI_2_5_FLASH = "gemini-2.5-flash"
+
+
+class LLMSkill(StrEnum):
+ LLM_TO_RETRIEVE = "llm_to_retrieve"
+ LLM_CHEAP_FOR_EASY_QUESTIONS = "llm_cheap_for_easy_questions"
+ LLM_TO_ANSWER_HARD_QUESTIONS = "llm_to_answer_hard_questions"
+ LLM_FOR_VISUAL_ANALYSIS = "llm_for_visual_analysis"
+ LLM_FOR_VISUAL_DESIGN = "llm_for_visual_design"
+ LLM_FOR_CREATIVE_WRITING = "llm_for_creative_writing"
+ LLM_TO_REASON = "llm_to_reason"
+ LLM_TO_REASON_ON_DIAGRAM = "llm_to_reason_on_diagram"
+ LLM_TO_ANALYZE_DATA = "llm_to_analyze_data"
+ LLM_TO_CODE = "llm_to_code"
+ LLM_TO_ANALYZE_LARGE_CODEBASE = "llm_to_analyze_large_codebase"
+
+ @property
+ def llm_recommendation(self) -> AvailableLLM:
+ match self:
+ case LLMSkill.LLM_TO_RETRIEVE:
+ return AvailableLLM.GEMINI_2_5_FLASH
+ case LLMSkill.LLM_CHEAP_FOR_EASY_QUESTIONS:
+ return AvailableLLM.GPT_5_MINI
+ case LLMSkill.LLM_TO_ANSWER_HARD_QUESTIONS:
+ return AvailableLLM.GPT_5
+ case LLMSkill.LLM_FOR_VISUAL_ANALYSIS:
+ return AvailableLLM.GEMINI_2_5_FLASH
+ case LLMSkill.LLM_FOR_VISUAL_DESIGN:
+ return AvailableLLM.GEMINI_2_5_FLASH
+ case LLMSkill.LLM_FOR_CREATIVE_WRITING:
+ return AvailableLLM.CLAUDE_4_1_OPUS
+ case LLMSkill.LLM_TO_REASON:
+ return AvailableLLM.CLAUDE_4_SONNET
+ case LLMSkill.LLM_TO_REASON_ON_DIAGRAM:
+ return AvailableLLM.GPT_5
+ case LLMSkill.LLM_TO_ANALYZE_DATA:
+ return AvailableLLM.CLAUDE_4_SONNET
+ case LLMSkill.LLM_TO_CODE:
+ return AvailableLLM.CLAUDE_4_SONNET
+ case LLMSkill.LLM_TO_ANALYZE_LARGE_CODEBASE:
+ return AvailableLLM.GEMINI_2_5_PRO
class PipeLLMSpec(PipeSpec):
"""Spec for LLM-based pipe operations in the Pipelex framework.
PipeLLM enables Large Language Model processing to generate text or structured output.
- Supports text, structured data, and image inputs with flexible prompt configuration
- and output structuring methods.
-
- Attributes:
- the_pipe_code: Pipe code. Must be snake_case.
- type: Fixed to "PipeLLM" for this pipe type.
- system_prompt_template: Template for system prompt with inline variables using $ syntax.
- system_prompt_template_name: Name reference to a system prompt template.
- Mutually exclusive with other system_prompt fields.
- system_prompt_name: Name reference to a system prompt.
- Mutually exclusive with other system_prompt fields.
- system_prompt: Direct system-level prompt to guide LLM behavior. Can be inline text
- or file reference ('file:path/to/prompt.md'). Mutually exclusive with
- other system_prompt fields.
- prompt_template: User prompt template with variable substitution. Use $ for inline
- variables (e.g., $topic) and @ for entire input content (e.g., @text_to_summarize).
- Note: Don't use @ or $ for image variables. Mutually exclusive with other
- prompt fields.
- template_name: Name reference to a prompt template. Mutually exclusive with other prompt fields.
- prompt_name: Name reference to a prompt. Mutually exclusive with other prompt fields.
- prompt: Static user prompt without variable injection. Mutually exclusive with other prompt fields.
- llm: LLM preset(s) configuration. Can be single preset or mapping for different
- generation modes (e.g., main, object_direct).
- llm_to_structure: LLM preset specifically for output structuring in preliminary_text mode.
- structuring_method: Method for structured output generation ('direct' or 'preliminary_text').
- Defaults to global configuration.
- prompt_template_to_structure: Prompt template for second step in preliminary_text mode.
- system_prompt_to_structure: System prompt for structuring step in preliminary_text mode.
+ Supports text, structured data, and image inputs.
+
+ Validation Rules:
nb_output: Fixed number of outputs to generate (e.g., 3 for exactly 3 outputs).
- Must be > 0. Mutually exclusive with multiple_output.
+ Must be > 1. Mutually exclusive with multiple_output.
multiple_output: Enables variable-length list generation. Default is false (single output).
Set to true for indeterminate number of outputs. Mutually exclusive with nb_output.
- Validation Rules:
- 1. System prompt fields are mutually exclusive (only one can be set).
- 2. User prompt fields are mutually exclusive (only one can be set).
- 3. Output cardinality: nb_output and multiple_output are mutually exclusive.
- 4. nb_output must be greater than 0 when specified.
- 5. Structuring method must be 'direct' or 'preliminary_text' when specified.
-
"""
- type: Literal["PipeLLM"] = "PipeLLM"
- category: Literal["PipeOperator"] = "PipeOperator"
- the_pipe_code: str = Field(description="Pipe code. Must be snake_case.")
- system_prompt_template: str | None = None
- system_prompt_template_name: str | None = None
- system_prompt_name: str | None = None
- system_prompt: str | None = None
-
- prompt_template: str | None = None
- template_name: str | None = None
- prompt_name: str | None = None
- prompt: str | None = None
-
- llm: LLMChoiceSpec | None = None
- llm_to_structure: LLMChoiceSpec | None = None
-
- structuring_method: StructuringMethod | None = None
- prompt_template_to_structure: str | None = None
- system_prompt_to_structure: str | None = None
-
- nb_output: int | None = None
- multiple_output: bool | None = None
-
- @field_validator("nb_output", mode="after")
- @staticmethod
- def validate_nb_output(value: int | None = None) -> int | None:
- if value and value < 1:
- msg = "PipeLLMBlueprint nb_output must be greater than 0"
- raise PipeDefinitionError(msg)
- return value
+ type: SkipJsonSchema[Literal["PipeLLM"]] = "PipeLLM"
+ category: SkipJsonSchema[Literal["PipeOperator"]] = "PipeOperator"
+ the_pipe_code: str = Field(description="Pipe code identifying the pipe. Must be snake_case.")
+
+ llm: LLMSkill | str = Field(description="The required skill of the LLM according to the task to be performed.")
+ temperature: float | None = Field(default=None, ge=0, le=1)
+ system_prompt: str | None = Field(default=None, description="A system-level prompt to guide the LLM's behavior, style and skills.")
+ prompt_template: str | None = Field(
+ description=(
+ "A template for the user prompt. Use `$` prefix for inline variables (e.g., `$topic`) and `@` prefix "
+ "to insert the content of an entire input (e.g., `@extracted_text`). "
+ "**Notes**: • Do not use `@` or `$` for image variables, declaring them as inputs is enough."
+ "• You can also use jinja2 syntax for conditional logic and for loops, but prefer `$` and `@` for simple variable insertions."
+ )
+ )
+
+ nb_output: int | None = Field(
+ default=None,
+ description=(
+ "Specifies exactly how many outputs to generate (e.g., `nb_output = 3` for exactly 3 outputs). "
+ "Set it if we need a fixed number of results."
+ ),
+ gt=1,
+ )
+ multiple_output: bool | None = Field(
+ default=None,
+ description=(
+ "Controls output generation mode. Set to `true` for variable-length list generation when we need an indeterminate number of outputs."
+ ),
+ )
+
+ @field_validator("llm", mode="before")
+ @classmethod
+ def validate_llm(cls, llm_value: str) -> LLMSkill:
+ return LLMSkill(llm_value)
@model_validator(mode="after")
def validate_multiple_output(self) -> Self:
- if excess_attributes_list := has_more_than_one_among_attributes_from_lists(
+ if excess_attributes_list := has_more_than_one_among_attributes_from_list(
self,
- attributes_lists=[
- ["nb_output", "multiple_output"],
- ["system_prompt", "system_prompt_name", "system_prompt_template", "system_prompt_template_name"],
- ["prompt", "prompt_name", "prompt_template", "template_name"],
- ],
+ attributes_list=["nb_output", "multiple_output"],
):
- msg = f"PipeLLMBlueprint should have no more than one of {excess_attributes_list} among them"
+ msg = f"PipeLLMSpec must have no more than one of {excess_attributes_list}"
raise PipeDefinitionError(msg)
return self
@override
def to_blueprint(self) -> PipeLLMBlueprint:
base_blueprint = super().to_blueprint()
- llm: LLMChoice | None = None
- if isinstance(self.llm, LLMSettingSpec):
- llm = LLMSetting(llm_handle=self.llm.llm_handle, temperature=self.llm.temperature, max_tokens=self.llm.max_tokens)
- elif isinstance(self.llm, str):
- llm = self.llm
-
- llm_to_structure: LLMChoice | None = None
- if isinstance(self.llm_to_structure, LLMSettingSpec):
- llm_to_structure = LLMSetting(
- llm_handle=self.llm_to_structure.llm_handle,
- temperature=self.llm_to_structure.temperature,
- max_tokens=self.llm_to_structure.max_tokens,
- )
- elif isinstance(self.llm_to_structure, str):
- llm_to_structure = self.llm_to_structure
+
+ # create llm choice as a str
+ llm_choice: LLMChoice
+ if isinstance(self.llm, LLMSkill):
+ llm_choice = self.llm.llm_recommendation.value
+ else:
+ llm_choice = LLMSkill(self.llm).llm_recommendation.value
+
+ # Make it a LLMSetting if temperature is provided
+ if self.temperature:
+ llm_choice = LLMSetting(llm_handle=llm_choice, temperature=self.temperature)
return PipeLLMBlueprint(
+ type="PipeLLM",
+ category="PipeOperator",
definition=base_blueprint.definition,
inputs=base_blueprint.inputs,
output=base_blueprint.output,
- type=self.type,
- category=self.category,
- system_prompt_template=self.system_prompt_template,
- system_prompt_template_name=self.system_prompt_template_name,
- system_prompt_name=self.system_prompt_name,
system_prompt=self.system_prompt,
prompt_template=self.prompt_template,
- template_name=self.template_name,
- prompt_name=self.prompt_name,
- prompt=self.prompt,
- llm=llm,
- llm_to_structure=llm_to_structure,
- structuring_method=self.structuring_method,
- prompt_template_to_structure=self.prompt_template_to_structure,
- system_prompt_to_structure=self.system_prompt_to_structure,
+ llm=llm_choice,
nb_output=self.nb_output,
multiple_output=self.multiple_output,
)
diff --git a/pipelex/libraries/pipelines/builder/pipe/pipe_ocr_spec.py b/pipelex/libraries/pipelines/builder/pipe/pipe_ocr_spec.py
index 8f2ce3723..197a6e97b 100644
--- a/pipelex/libraries/pipelines/builder/pipe/pipe_ocr_spec.py
+++ b/pipelex/libraries/pipelines/builder/pipe/pipe_ocr_spec.py
@@ -1,16 +1,35 @@
-from typing import Literal
+from typing import TYPE_CHECKING, Literal
-from pydantic import Field
+from pydantic import Field, field_validator
+from pydantic.json_schema import SkipJsonSchema
from typing_extensions import override
+from pipelex.exceptions import PipeDefinitionError
from pipelex.libraries.pipelines.builder.pipe.pipe_signature import PipeSpec
from pipelex.pipe_operators.ocr.pipe_ocr_blueprint import PipeOcrBlueprint
from pipelex.types import StrEnum
+if TYPE_CHECKING:
+ from pipelex.cogt.ocr.ocr_setting import OcrChoice
-class RecommendedOcrPreset(StrEnum):
+
+class AvailableOcr(StrEnum):
BASE_OCR_MISTRAL = "base_ocr_mistral"
- BASE_OCR_PYPDFIUM2 = "base_ocr_pypdfium2"
+ # BASE_OCR_PYPDFIUM2 = "base_ocr_pypdfium2"
+
+
+class OcrSkill(StrEnum):
+ EXTRACT_TEXT_FROM_VISUALS = "extract_text_from_visuals"
+ EXTARCT_TEXT_FROM_PDF = "extract_text_from_pdf"
+
+ @property
+ def ocr_recommendation(self) -> AvailableOcr:
+ match self:
+ case OcrSkill.EXTRACT_TEXT_FROM_VISUALS:
+ return AvailableOcr.BASE_OCR_MISTRAL
+ case OcrSkill.EXTARCT_TEXT_FROM_PDF:
+ # TODO: Debug the BaseOcrPypdfium2
+ return AvailableOcr.BASE_OCR_MISTRAL
class PipeOcrSpec(PipeSpec):
@@ -20,41 +39,55 @@ class PipeOcrSpec(PipeSpec):
Supports various OCR platforms and output configurations including image detection,
caption generation, and page rendering.
- VERY IMPORTANT: THE INPUT OF THE PIPEOCR MUST BE either an image or a pdf or a concept which refines one of them.
-
- Attributes:
- the_pipe_code: Pipe code. Must be snake_case.
- type: Fixed to "PipeOcr" for this pipe type.
- ocr: name of the OCR model or handle or preset or setting
- page_images: Whether to include detected images in the OCR output. When enabled,
- extracts and returns embedded images found in documents.
- page_image_captions: Whether to generate captions for detected images using AI.
- Useful for understanding image content in documents.
- page_views: Whether to include rendered page views in the output. Provides
- visual representation of document pages.
- page_views_dpi: DPI (dots per inch) resolution for rendered page views.
- Higher values provide better quality but larger file sizes.
- Defaults to configuration setting.
+ Validation Rules:
+ - inputs dict must have exactly one input entry, and the value must be either `Image` or `PDF`.
"""
- type: Literal["PipeOcr"] = "PipeOcr"
- category: Literal["PipeOperator"] = "PipeOperator"
+ type: SkipJsonSchema[Literal["PipeOcr"]] = "PipeOcr"
+ category: SkipJsonSchema[Literal["PipeOperator"]] = "PipeOperator"
the_pipe_code: str = Field(description="Pipe code. Must be snake_case.")
- ocr: RecommendedOcrPreset | str = Field(description="Use one of the recommended OCR presets")
- page_images: bool | None = None
- page_image_captions: bool | None = None
- page_views: bool | None = None
- page_views_dpi: int | None = None
+ ocr: OcrSkill | str = Field(description="Use one of the recommended OCR choices")
+ page_images: bool | None = Field(default=None, description="Whether to include detected images in the OCR output.")
+ page_image_captions: bool | None = Field(default=None, description="Whether to generate captions for detected images using AI.")
+ page_views: bool | None = Field(default=None, description="Whether to include rendered page views in the output.")
+
+ @field_validator("ocr", mode="before")
+ @classmethod
+ def validate_ocr(cls, ocr_value: str) -> OcrSkill:
+ return OcrSkill(ocr_value)
+
+ @field_validator("inputs", mode="before")
+ @classmethod
+ def validate_ocr_inputs(cls, inputs_value: dict[str, str] | None) -> dict[str, str] | None:
+ if inputs_value is None:
+ msg = "PipeOcr must have exactly one input which must be either`Image` or `PDF`."
+ raise PipeDefinitionError(msg)
+ if len(inputs_value) != 1:
+ msg = "PipeOcr must have exactly one input which must be either`Image` or `PDF`."
+ raise PipeDefinitionError(msg)
+ return inputs_value
@override
def to_blueprint(self) -> PipeOcrBlueprint:
base_blueprint = super().to_blueprint()
+ # create ocr choice as a str
+ ocr: OcrChoice
+ if isinstance(self.ocr, OcrSkill):
+ ocr = self.ocr.ocr_recommendation.value
+ else:
+ ocr = OcrSkill(self.ocr).ocr_recommendation.value
+
return PipeOcrBlueprint(
+ source=None,
definition=base_blueprint.definition,
inputs=base_blueprint.inputs,
output=base_blueprint.output,
type=self.type,
category=self.category,
- ocr=self.ocr,
+ ocr=ocr,
+ page_images=self.page_images,
+ page_image_captions=self.page_image_captions,
+ page_views=self.page_views,
+ page_views_dpi=None,
)
diff --git a/pipelex/libraries/pipelines/builder/pipe/pipe_parallel_spec.py b/pipelex/libraries/pipelines/builder/pipe/pipe_parallel_spec.py
index 42e63175f..c43e9e29e 100644
--- a/pipelex/libraries/pipelines/builder/pipe/pipe_parallel_spec.py
+++ b/pipelex/libraries/pipelines/builder/pipe/pipe_parallel_spec.py
@@ -18,34 +18,24 @@ class PipeParallelSpec(PipeSpec):
for independent operations. All parallel pipes receive the same input context
and their outputs can be combined or kept separate.
- Attributes:
- the_pipe_code: Pipe code. Must be snake_case.
- type: Fixed to "PipeParallel" for this pipe type.
- parallels: List of SubPipeSpec instances to execute concurrently.
- All pipes run simultaneously with access to the same input context.
- add_each_output: Whether to include individual pipe outputs in the combined
- result. Default is True. When False, only combined_output is used.
- combined_output: Optional concept string/code for the combined output structure.
- When specified, all parallel outputs are merged into this concept.
-
Validation Rules:
1. Parallels list must not be empty.
2. Each parallel step must be a valid SubPipeSpec.
- 3. combined_output, when specified, must be a valid concept string or code.
- 4. Pipe codes in parallels must reference existing pipes.
+ 3. combined_output, when specified, must be a valid ConceptCode in PascalCase.
+ 4. Pipe codes in parallels must reference existing pipes (snake_case).
"""
type: Literal["PipeParallel"] = "PipeParallel"
category: Literal["PipeController"] = "PipeController"
the_pipe_code: str = Field(description="Pipe code. Must be snake_case.")
- parallels: list[SubPipeSpec]
- add_each_output: bool = False
- combined_output: str | None = None
+ parallels: list[SubPipeSpec] = Field(description="List of SubPipeSpec instances to execute concurrently.")
+ add_each_output: bool = Field(description="Whether to include individual pipe outputs in the combined result.")
+ combined_output: str | None = Field(default=None, description="Optional ConceptCode in PascalCasefor the combined output structure.")
@field_validator("combined_output", mode="before")
- @staticmethod
- def validate_combined_output(combined_output: str) -> str:
+ @classmethod
+ def validate_combined_output(cls, combined_output: str) -> str:
if combined_output:
ConceptSpec.validate_concept_string_or_code(concept_string_or_code=combined_output)
return combined_output
@@ -57,7 +47,11 @@ class PipeParallelSpec(PipeSpec):
"PipeParallel requires either add_each_output to be True or combined_output to be set, "
"or both, otherwise the pipe won't output anything"
)
- raise PipeDefinitionError(msg)
+ raise PipeDefinitionError(
+ message=msg,
+ pipe_code=self.the_pipe_code,
+ description=self.definition,
+ )
return self
@override
diff --git a/pipelex/libraries/pipelines/builder/pipe/pipe_sequence_spec.py b/pipelex/libraries/pipelines/builder/pipe/pipe_sequence_spec.py
index 2921c0a2e..a508cf74b 100644
--- a/pipelex/libraries/pipelines/builder/pipe/pipe_sequence_spec.py
+++ b/pipelex/libraries/pipelines/builder/pipe/pipe_sequence_spec.py
@@ -1,6 +1,7 @@
from typing import Literal
from pydantic import Field
+from pydantic.json_schema import SkipJsonSchema
from typing_extensions import override
from pipelex.libraries.pipelines.builder.pipe.pipe_signature import PipeSpec
@@ -9,30 +10,17 @@ from pipelex.pipe_controllers.sequence.pipe_sequence_blueprint import PipeSequen
class PipeSequenceSpec(PipeSpec):
- """Spec for sequential pipe execution in the Pipelex framework.
-
- PipeSequence orchestrates the execution of multiple pipes in a defined order,
+ """PipeSequenceSpec orchestrates the execution of multiple pipes in a defined order,
where each pipe's output can be used as input for subsequent pipes. This enables
building complex data processing workflows with step-by-step transformations.
-
- Attributes:
- the_pipe_code: Pipe code. Must be snake_case.
- type: Fixed to "PipeSequence" for this pipe type.
- steps: Ordered list of SubPipeBlueprint instances defining the pipes
- to execute. Each step runs after the previous one completes,
- with access to all prior outputs in the context.
-
- Validation Rules:
- 1. Steps list must not be empty.
- 2. Each step must be a valid SubPipeBlueprint instance.
- 3. Pipe codes referenced in steps must exist in the pipeline.
-
"""
- type: Literal["PipeSequence"] = "PipeSequence"
- category: Literal["PipeController"] = "PipeController"
+ type: SkipJsonSchema[Literal["PipeSequence"]] = "PipeSequence"
+ category: SkipJsonSchema[Literal["PipeController"]] = "PipeController"
the_pipe_code: str = Field(description="Pipe code. Must be snake_case.")
- steps: list[SubPipeSpec]
+ steps: list[SubPipeSpec] = Field(
+ description=("List of SubPipeSpec instances to execute sequentially. Each step runs after the previous one completes.")
+ )
@override
def to_blueprint(self) -> PipeSequenceBlueprint:
diff --git a/pipelex/libraries/pipelines/builder/pipe/pipe_signature.py b/pipelex/libraries/pipelines/builder/pipe/pipe_signature.py
index e100ac393..f40edb0c1 100644
--- a/pipelex/libraries/pipelines/builder/pipe/pipe_signature.py
+++ b/pipelex/libraries/pipelines/builder/pipe/pipe_signature.py
@@ -6,63 +6,43 @@ from pipelex.core.pipes.exceptions import PipeBlueprintError
from pipelex.core.pipes.pipe_blueprint import AllowedPipeCategories, AllowedPipeTypes, PipeBlueprint
from pipelex.core.pipes.pipe_input_blueprint import InputRequirementBlueprint
from pipelex.core.stuffs.stuff_content import StructuredContent
-from pipelex.libraries.pipelines.builder.concept.concept_spec import ConceptSpec, ConceptSpecDraft
-from pipelex.libraries.pipelines.builder.pipe.inputs_spec import InputRequirementSpec
+from pipelex.libraries.pipelines.builder.concept.concept_spec import ConceptSpec
from pipelex.tools.misc.string_utils import is_snake_case
class PipeSignature(StructuredContent):
- code: str = Field(description="Pipe code. Must be snake_case.")
- type: AllowedPipeTypes = Field(description="Pipe type.")
+ """PipeSignature is a contract for a pipe.
+ It defines the inputs, outputs, and the purpose of the pipe.
+ It doesn't go into the details of how it does it.
+ """
+
+ code: str = Field(description="Pipe code identifying the pipe. Must be snake_case.")
category: AllowedPipeCategories = Field(description="Pipe category.")
- definition: str = Field(description="What the pipe does")
- inputs: dict[str, ConceptSpecDraft] = Field(description="Pipe inputs: key is the concept code in pascal Case.")
- result: str = Field(description="The name of the result of the pipe. Must be snake_case. It will be used in the inputs of the next pipes.")
- output: ConceptSpecDraft = Field(description="Concept as output")
- important_features: dict[str, Any] | None = Field(
- default=None,
- description="Important features specific to this pipe type "
- "(e.g., referenced pipe codes for controllers, specific configuration for operators)",
+ type: AllowedPipeTypes = Field(description="Pipe type.")
+ description: str = Field(description="What the pipe does")
+ inputs: dict[str, str] = Field(
+ description="Pipe inputs: keys are the input variable_names in snake_case, values are the ConceptCodes in PascalCase."
+ )
+ result: str = Field(
+ description="variable_name for the result of the pipe. Must be snake_case. It could be referenced as input in a following pipe."
)
+ output: str = Field(description="Just the output ConceptCode in PascalCase")
+ pipe_dependencies: list[str] = Field(description="List of pipe codes that this pipe depends on. This is for the PipeControllers")
class PipeSpec(StructuredContent):
- """Spec defining a pipe component in the Pipelex framework.
-
- Pipes are the fundamental processing units in Pipelex workflows. They transform
- input concepts into output concepts through various operations like LLM processing,
- image generation, OCR, or custom functions.
-
- Attributes:
- type: The pipe type (PipeFunc, PipeLLM, PipeImgGen, PipeOcr, PipeBatch,
- PipeCondition, PipeParallel, PipeSequence). Uses Any type to avoid
- type override conflicts but validated at runtime.
- category: The pipe category (PipeOperator, PipeController). Uses Any type to avoid
- category override conflicts but validated at runtime.
- The pipe controllers are PipeSequence, PipeParallel, PipeCondition, PipeBatch.
- The pipe operators are PipeFunc, PipeLLM, PipeImgGen, PipeOcr, PipeCompose.
- definition: Natural language description of what the pipe does.
- inputs: Input concept specifications. should be an InputRequirementBlueprint
- Dictionary keys are input names in snake_case, values are concept specifications in PascalCase.
- output: Output concept code in PascalCase format.
-
- Validation Rules:
- 1. Pipe type: Must be one of the AllowedPipeTypes enum values.
- 2. Output concept: Must be valid concept string or code in PascalCase.
- 3. Input concepts: When provided, must use PascalCase for concept references.
- 4. Pipe codes: When validating pipe codes, must be in snake_case format.
-
+ """Spec defining a pipe: an executable component with a clear contract defined by its inputs and output.
+ There are two categories of pipes: controllers and operators.
+ Controllers are used to control the flow of the pipeline, and operators are used to perform specific tasks.
"""
- type: Any = Field(description=f"Pipe type. Must be one of: {AllowedPipeTypes}")
- category: Any = Field(description=f"Pipe category. Must be one of: {AllowedPipeCategories}")
+ type: Any = Field(description=f"Pipe type. It is defined with type `Any` but validated at runtime and it must be one of: {AllowedPipeTypes}")
+ category: Any = Field(
+ description=f"Pipe category. It is defined with type `Any` but validated at runtime and it must be one of: {AllowedPipeCategories}"
+ )
definition: str | None = Field(description="Natural language description of what the pipe does.")
- inputs: dict[str, str | InputRequirementSpec] | None = Field(
- description=(
- "Input concept specifications. Can be either: "
- "InputRequirementSpec with additional constraints"
- "Dictionary keys are input names, values are concept specifications. If Its the concept itself, use the concept code in PascalCase."
- ),
+ inputs: dict[str, str] = Field(
+ description=("Input concept specifications. The keys are input names in snake_case. Each value must be a ConceptCode in PascalCase"),
)
output: str = Field(description="Output concept code in PascalCase format!! Very important")
@@ -74,12 +54,24 @@ class PipeSpec(StructuredContent):
raise PipeBlueprintError(msg)
return value
- @field_validator("output", mode="before")
+ @field_validator("output", mode="after")
@staticmethod
def validate_concept_string_or_code(output: str) -> str:
ConceptSpec.validate_concept_string_or_code(concept_string_or_code=output)
return output
+ @field_validator("inputs", mode="after")
+ @staticmethod
+ def validate_inputs(inputs: dict[str, str] | None) -> dict[str, str] | None:
+ if inputs is None:
+ return None
+ for input_name, concept_code in inputs.items():
+ if not is_snake_case(input_name):
+ msg = f"Invalid input name syntax '{input_name}'. Must be in snake_case."
+ raise PipeBlueprintError(msg)
+ ConceptSpec.validate_concept_string_or_code(concept_string_or_code=concept_code)
+ return inputs
+
@classmethod
def validate_pipe_code_syntax(cls, pipe_code: str) -> str:
if not is_snake_case(pipe_code):
@@ -88,14 +80,13 @@ class PipeSpec(StructuredContent):
return pipe_code
def to_blueprint(self) -> PipeBlueprint:
- converted_inputs: dict[str, str | InputRequirementBlueprint] | None = None
- if self.inputs is not None:
+ converted_inputs: dict[str, str | InputRequirementBlueprint] | None
+ if not self.inputs:
+ converted_inputs = None
+ else:
converted_inputs = {}
- for input_name, input_spec in self.inputs.items():
- if isinstance(input_spec, InputRequirementSpec):
- converted_inputs[input_name] = input_spec.to_blueprint()
- else:
- converted_inputs[input_name] = InputRequirementBlueprint(concept=input_spec)
+ for input_name, concept_code in self.inputs.items():
+ converted_inputs[input_name] = InputRequirementBlueprint(concept=concept_code)
return PipeBlueprint(
definition=self.definition,
diff --git a/pipelex/libraries/pipelines/images.plx b/pipelex/libraries/pipelines/images.plx
index 43338aabf..fca40590f 100644
--- a/pipelex/libraries/pipelines/images.plx
+++ b/pipelex/libraries/pipelines/images.plx
@@ -26,7 +26,6 @@ type = "PipeImgGen"
definition = "Generate an image"
inputs = { prompt = "ImgGenPrompt" }
output = "Image"
-nb_steps = 2
[pipe.generate_photo]
@@ -34,5 +33,4 @@ type = "PipeImgGen"
definition = "Generate a photo"
inputs = { prompt = "ImgGenPrompt" }
output = "images.Photo"
-nb_steps = 8
diff --git a/pipelex/libraries/templates/base_templates.toml b/pipelex/libraries/templates/base_templates.toml
deleted file mode 100644
index 484fecacf..000000000
--- a/pipelex/libraries/templates/base_templates.toml
+++ /dev/null
@@ -1,17 +0,0 @@
-[generic_prompts]
-
-structure_from_preliminary_text_system = "You are a data modeling expert specialized in extracting structure from text."
-# TODO: Should be a proper jinja2
-structure_from_preliminary_text_user = """
-Your job is to extract and structure information from a text.
-Here is the text:
-{preliminary_text}
-
-Now generate the JSON in the required format.
-Do not create information that is not in the text.
-"""
-
-[test_prompts]
-
-jinja2_test_template = "I want a {{ place_holder }} t-shirt."
-
diff --git a/pipelex/pipe_controllers/condition/pipe_condition.py b/pipelex/pipe_controllers/condition/pipe_condition.py
index 7905e8c35..1a38a5675 100644
--- a/pipelex/pipe_controllers/condition/pipe_condition.py
+++ b/pipelex/pipe_controllers/condition/pipe_condition.py
@@ -9,12 +9,13 @@ from pipelex.config import StaticValidationReaction, get_config
from pipelex.core.concepts.concept_factory import ConceptFactory
from pipelex.core.concepts.concept_native import NATIVE_CONCEPTS_DATA, NativeConceptEnum, NativeConceptManager
from pipelex.core.memory.working_memory import WorkingMemory
+from pipelex.core.pipes.pipe_abstract import PipeAbstract
from pipelex.core.pipes.pipe_input import PipeInputSpec
from pipelex.core.pipes.pipe_input_blueprint import InputRequirementBlueprint
from pipelex.core.pipes.pipe_input_factory import PipeInputSpecFactory
from pipelex.core.pipes.pipe_output import PipeOutput
from pipelex.core.pipes.pipe_run_params import PipeRunParams
-from pipelex.core.pipes.specific_pipe import SpecificPipe
+from pipelex.core.pipes.specific_pipe import SpecificPipe, SpecificPipeCodesEnum
from pipelex.exceptions import (
DryRunError,
PipeConditionError,
@@ -25,13 +26,13 @@ from pipelex.exceptions import (
StaticValidationErrorType,
WorkingMemoryStuffNotFoundError,
)
-from pipelex.hub import get_pipe_router, get_pipeline_tracker, get_required_pipe
+from pipelex.hub import get_content_generator, get_pipe_router, get_pipeline_tracker, get_required_pipe, get_template_provider
from pipelex.pipe_controllers.condition.pipe_condition_details import PipeConditionDetails, PipeConditionPipeMap
from pipelex.pipe_controllers.pipe_controller import PipeController
-from pipelex.pipe_operators.compose.pipe_compose_blueprint import PipeComposeBlueprint
-from pipelex.pipe_operators.compose.pipe_compose_factory import PipeComposeFactory
from pipelex.pipe_works.pipe_job_factory import PipeJobFactory
-from pipelex.pipeline.job_metadata import JobCategory, JobMetadata
+from pipelex.pipeline.job_metadata import JobMetadata
+from pipelex.tools.templating.jinja2_required_variables import detect_jinja2_required_variables
+from pipelex.tools.templating.jinja2_template_category import Jinja2TemplateCategory
from pipelex.tools.typing.validation_utils import has_exactly_one_among_attributes_from_list
from pipelex.types import Self
@@ -67,7 +68,7 @@ class PipeCondition(PipeController):
f"not matching the output concept code '{pipe.output.concept_string}' of the pipe '{pipe_condition_pipe_map.pipe_code}'"
)
raise PipeConditionError(msg)
- if self.default_pipe_code:
+ if self.default_pipe_code and self.default_pipe_code not in SpecificPipeCodesEnum.value_list():
default_pipe = get_required_pipe(pipe_code=self.default_pipe_code)
if self.output.concept_string not in (
default_pipe.output.concept_string,
@@ -128,12 +129,13 @@ class PipeCondition(PipeController):
required_variables: set[str] = set()
# TODO: use jinja2 directly without going though a pipe
# Variables from the expression/expression_template
- pipe_compose = PipeComposeFactory.make_pipe_compose_from_template_str(
- domain=self.domain,
- template_str=self.applied_expression_template,
- inputs=self.inputs,
+ expression_required_variables = detect_jinja2_required_variables(
+ template_category=Jinja2TemplateCategory.LLM_PROMPT,
+ template_provider=get_template_provider(),
+ jinja2_name=None,
+ jinja2=self.applied_expression_template,
)
- required_variables.update(pipe_compose.required_variables())
+ required_variables.update(expression_required_variables)
# Variables from the pipe_map
for pipe_code in self.pipe_dependencies():
@@ -162,13 +164,14 @@ class PipeCondition(PipeController):
needed_inputs = PipeInputSpecFactory.make_empty()
# 1. Add the variables from the expression/expression_template
- pipe_compose = PipeComposeFactory.make_pipe_compose_from_template_str(
- domain=self.domain,
- template_str=self.applied_expression_template,
- inputs=self.inputs,
+ required_variables = detect_jinja2_required_variables(
+ template_category=Jinja2TemplateCategory.LLM_PROMPT,
+ template_provider=get_template_provider(),
+ jinja2_name=None,
+ jinja2=self.applied_expression_template,
)
- for var_name in pipe_compose.required_variables():
+ for var_name in required_variables:
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
@@ -257,64 +260,42 @@ class PipeCondition(PipeController):
for pipe_condition_pipe_map in self.pipe_map
if not SpecificPipe.is_continue(pipe_condition_pipe_map.pipe_code)
]
- if self.default_pipe_code:
+ if self.default_pipe_code and self.default_pipe_code not in SpecificPipeCodesEnum.value_list():
pipe_codes.append(self.default_pipe_code)
return set(pipe_codes)
- @override
- async def _run_controller_pipe(
+ async def _evaluate_expression_and_select_pipe(
self,
- job_metadata: JobMetadata,
working_memory: WorkingMemory,
- pipe_run_params: PipeRunParams,
- output_name: str | None = None,
- ) -> PipeOutput:
- log.dev(f"{self.class_name} generating a '{self.output.code}'")
+ ) -> PipeAbstract:
+ """Evaluate the conditional expression and select the appropriate pipe.
- # TODO: restore pipe_layer feature
- # pipe_run_params.push_pipe_code(pipe_code=pipe_code)
+ Args:
+ working_memory: The working memory context for evaluation
- # Convert PipeInputSpec to blueprint format
- inputs_blueprint: dict[str, str | InputRequirementBlueprint] = {}
- for var_name, requirement in self.inputs.root.items():
- inputs_blueprint[var_name] = InputRequirementBlueprint(
- concept=requirement.concept.concept_string,
- multiplicity=requirement.multiplicity,
- )
+ Returns:
+ A tuple of (evaluated_expression, chosen_pipe_code)
+
+ Raises:
+ PipeConditionError: If expression evaluation fails or no matching pipe is found
+ """
+ content_generator = get_content_generator()
+ # Evaluate the expression using Jinja2 templating
- pipe_compose_blueprint = PipeComposeBlueprint(
- definition="Jinja2 template for pipe condition evaluation",
+ evaluated_expression = await content_generator.make_jinja2_text(
+ context=working_memory.generate_jinja2_context(),
jinja2=self.applied_expression_template,
- inputs=inputs_blueprint,
- output=self.output.code,
+ template_category=Jinja2TemplateCategory.LLM_PROMPT,
)
- # TODO: use jinja2 directly without going though a pipe
- pipe_compose = PipeComposeFactory.make_from_blueprint(
- domain=self.domain,
- pipe_code="evaluation_for_pipe_condition",
- blueprint=pipe_compose_blueprint,
- )
- jinja2_job_metadata = job_metadata.copy_with_update(
- updated_metadata=JobMetadata(
- job_category=JobCategory.JINJA2_JOB,
- ),
- )
- log.debug(f"Jinja2 expression: {self.applied_expression_template}")
- evaluated_expression = (
- await pipe_compose.run_pipe(
- job_metadata=jinja2_job_metadata,
- working_memory=working_memory,
- pipe_run_params=pipe_run_params,
- )
- ).main_stuff_as_str.strip()
-
+ # Validate the evaluated expression
if not evaluated_expression or evaluated_expression == "None":
error_msg = f"Conditional expression returned an empty string in pipe {self.code}:"
error_msg += f"\n\nExpression: {self.applied_expression_template}"
raise PipeConditionError(error_msg)
log.debug(f"evaluated_expression: '{evaluated_expression}'")
+ # Add alias if configured
log.debug(f"add_alias: {evaluated_expression} -> {self.add_alias_from_expression_to}")
if self.add_alias_from_expression_to:
working_memory.add_alias(
@@ -322,6 +303,7 @@ class PipeCondition(PipeController):
target=self.add_alias_from_expression_to,
)
+ # Select the pipe based on the evaluated expression
chosen_pipe_code = next(
(
pipe_condition_pipe_map.pipe_code
@@ -330,20 +312,50 @@ class PipeCondition(PipeController):
),
self.default_pipe_code,
)
+ # Validate that a pipe was found
if not chosen_pipe_code:
error_msg = f"No pipe code found for evaluated expression '{evaluated_expression}' in pipe {self.code}:"
error_msg += f"\n\nExpression: {self.applied_expression_template}"
error_msg += f"\n\nPipe map: {self.pipe_map}"
raise PipeConditionError(error_msg)
- if SpecificPipe.is_continue(chosen_pipe_code):
+ return get_required_pipe(pipe_code=chosen_pipe_code)
+
+ @override
+ async def _run_controller_pipe(
+ self,
+ job_metadata: JobMetadata,
+ working_memory: WorkingMemory,
+ pipe_run_params: PipeRunParams,
+ output_name: str | None = None,
+ ) -> PipeOutput:
+ log.dev(f"{self.class_name} generating a '{self.output.code}'")
+
+ # TODO: restore pipe_layer feature
+ # pipe_run_params.push_pipe_code(pipe_code=pipe_code)
+
+ # Convert PipeInputSpec to blueprint format
+ inputs_blueprint: dict[str, str | InputRequirementBlueprint] = {}
+ for var_name, requirement in self.inputs.root.items():
+ inputs_blueprint[var_name] = InputRequirementBlueprint(
+ concept=requirement.concept.concept_string,
+ multiplicity=requirement.multiplicity,
+ )
+
+ chosen_pipe = await self._evaluate_expression_and_select_pipe(working_memory=working_memory)
+
+ # Handle continue case
+ if SpecificPipe.is_continue(chosen_pipe.code):
return PipeOutput(working_memory=working_memory)
+ # Create condition details for tracking
condition_details = self._make_pipe_condition_details(
- evaluated_expression=evaluated_expression,
- chosen_pipe_code=chosen_pipe_code,
+ evaluated_expression=self.applied_expression_template,
+ chosen_pipe_code=chosen_pipe.code,
)
- required_variables = pipe_compose.required_variables()
+
+ # Get required variables and validate they exist in working memory
+ required_variables = chosen_pipe.required_variables()
log.debug(required_variables, title=f"Required variables for PipeCondition '{self.code}'")
required_stuff_names = {required_variable for required_variable in required_variables if not required_variable.startswith("_")}
try:
@@ -355,6 +367,7 @@ class PipeCondition(PipeController):
msg = f"Some required stuff(s) not found: {error_details}"
raise PipeInputError(msg) from exc
+ # Track condition steps
for required_stuff in required_stuffs:
get_pipeline_tracker().add_condition_step(
from_stuff=required_stuff,
@@ -364,16 +377,19 @@ class PipeCondition(PipeController):
comment="PipeCondition required for condition",
)
- log.debug(f"Chosen pipe: {chosen_pipe_code}")
+ # Execute the chosen pipe
+ log.debug(f"Chosen pipe: {chosen_pipe.code}")
pipe_output = await get_pipe_router().run(
pipe_job=PipeJobFactory.make_pipe_job(
- pipe=get_required_pipe(pipe_code=chosen_pipe_code),
+ pipe=chosen_pipe,
job_metadata=job_metadata,
working_memory=working_memory,
pipe_run_params=pipe_run_params,
output_name=output_name,
),
)
+
+ # Track choice step
get_pipeline_tracker().add_choice_step(
from_condition=condition_details,
to_stuff=pipe_output.main_stuff,
@@ -413,13 +429,12 @@ class PipeCondition(PipeController):
# 2. Validate that the expression template is valid
try:
- pipe_compose = PipeComposeFactory.make_pipe_compose_from_template_str(
- domain=self.domain,
- template_str=self.applied_expression_template,
- inputs=self.inputs,
+ required_variables = detect_jinja2_required_variables(
+ template_category=Jinja2TemplateCategory.LLM_PROMPT,
+ template_provider=get_template_provider(),
+ jinja2_name=None,
+ jinja2=self.applied_expression_template,
)
- # Get required variables to validate the template syntax
- required_variables = pipe_compose.required_variables()
log.debug(f"Expression template is valid, requires variables: {required_variables}")
except Exception as exc:
log.error(f"Dry run failed: invalid expression template: {exc}")
@@ -439,6 +454,8 @@ class PipeCondition(PipeController):
missing_pipes: list[str] = []
for pipe_code in all_pipe_codes:
+ if pipe_code in SpecificPipeCodesEnum.value_list():
+ continue
try:
get_required_pipe(pipe_code=pipe_code)
log.debug(f"Pipe '{pipe_code}' exists and is accessible")
diff --git a/pipelex/pipe_controllers/parallel/pipe_parallel_blueprint.py b/pipelex/pipe_controllers/parallel/pipe_parallel_blueprint.py
index 9351f0814..d8174a418 100644
--- a/pipelex/pipe_controllers/parallel/pipe_parallel_blueprint.py
+++ b/pipelex/pipe_controllers/parallel/pipe_parallel_blueprint.py
@@ -17,8 +17,8 @@ class PipeParallelBlueprint(PipeBlueprint):
combined_output: str | None = None
@field_validator("combined_output", mode="before")
- @staticmethod
- def validate_combined_output(combined_output: str) -> str:
+ @classmethod
+ def validate_combined_output(cls, combined_output: str) -> str:
if combined_output:
ConceptBlueprint.validate_concept_string_or_code(concept_string_or_code=combined_output)
return combined_output
diff --git a/pipelex/pipe_controllers/parallel/pipe_parallel_factory.py b/pipelex/pipe_controllers/parallel/pipe_parallel_factory.py
index af35e31d2..9a6eb693d 100644
--- a/pipelex/pipe_controllers/parallel/pipe_parallel_factory.py
+++ b/pipelex/pipe_controllers/parallel/pipe_parallel_factory.py
@@ -28,16 +28,18 @@ class PipeParallelFactory(PipeFactoryProtocol[PipeParallelBlueprint, PipeParalle
parallel_sub_pipes: list[SubPipe] = []
for sub_pipe_blueprint in blueprint.parallels:
if not sub_pipe_blueprint.result:
- msg = "PipeParallel requires a result specified for each parallel sub pipe"
- raise PipeDefinitionError(msg)
+ msg = "Unexpected error in pipe '{pipe_code}': PipeParallel requires a result specified for each parallel sub pipe"
+ raise PipeDefinitionError(
+ message=msg, domain_code=domain, pipe_code=pipe_code, description=blueprint.definition, source=blueprint.source
+ )
sub_pipe = SubPipeFactory.make_from_blueprint(sub_pipe_blueprint, concept_codes_from_the_same_domain=concept_codes_from_the_same_domain)
parallel_sub_pipes.append(sub_pipe)
if not blueprint.add_each_output and not blueprint.combined_output:
msg = (
- "Unexpected error:PipeParallel requires either add_each_output to be True or combined_output to be set, "
+ f"Unexpected error in pipe '{pipe_code}': PipeParallel requires either add_each_output to be True or combined_output to be set, "
"or both, otherwise the pipe won't output anything"
)
- raise PipeDefinitionError(msg)
+ raise PipeDefinitionError(message=msg, domain_code=domain, pipe_code=pipe_code, description=blueprint.definition, source=blueprint.source)
if blueprint.combined_output:
combined_output_domain_and_code = ConceptFactory.make_domain_and_concept_code_from_concept_string_or_code(
diff --git a/pipelex/pipe_controllers/pipe_controller.py b/pipelex/pipe_controllers/pipe_controller.py
index 8211f7449..bab1babb7 100644
--- a/pipelex/pipe_controllers/pipe_controller.py
+++ b/pipelex/pipe_controllers/pipe_controller.py
@@ -14,6 +14,10 @@ from pipelex.pipeline.job_metadata import JobMetadata
class PipeController(PipeAbstract):
category: Literal["PipeController"] = "PipeController"
+ @property
+ def class_name(self) -> str:
+ return self.__class__.__name__
+
@override
async def run_pipe(
self,
diff --git a/pipelex/pipe_controllers/sub_pipe.py b/pipelex/pipe_controllers/sub_pipe.py
index 1ddff16f8..a839e572e 100644
--- a/pipelex/pipe_controllers/sub_pipe.py
+++ b/pipelex/pipe_controllers/sub_pipe.py
@@ -121,8 +121,8 @@ class SubPipe(BaseModel):
raise PipeInputError(msg) from exc
log.verbose(required_stuffs, title=f"Required stuffs for {self.pipe_code}")
# This is the only line that changes between run and dry_run
+
if sub_pipe_run_params.run_mode == PipeRunMode.DRY:
- sub_pipe_run_params.run_mode = PipeRunMode.DRY
pipe_output = await sub_pipe.run_pipe(
job_metadata=job_metadata,
working_memory=working_memory,
diff --git a/pipelex/pipe_operators/compose/pipe_compose.py b/pipelex/pipe_operators/compose/pipe_compose.py
index 7d5399fe6..5d41bd1b9 100644
--- a/pipelex/pipe_operators/compose/pipe_compose.py
+++ b/pipelex/pipe_operators/compose/pipe_compose.py
@@ -132,7 +132,7 @@ class PipeCompose(PipeOperator[PipeComposeOutput]):
msg = f"PipeCompose does not suppport multiple outputs, got output_multiplicity = {pipe_run_params.output_multiplicity}"
raise PipeRunParamsError(msg)
- context: dict[str, Any] = working_memory.generate_context()
+ context: dict[str, Any] = working_memory.generate_jinja2_context()
if pipe_run_params:
context.update(**pipe_run_params.params)
if self.extra_context:
diff --git a/pipelex/pipe_operators/func/pipe_func.py b/pipelex/pipe_operators/func/pipe_func.py
index 932925e3e..fff8a204d 100644
--- a/pipelex/pipe_operators/func/pipe_func.py
+++ b/pipelex/pipe_operators/func/pipe_func.py
@@ -1,3 +1,4 @@
+import asyncio
from typing import Literal, cast, get_type_hints
from typing_extensions import override
@@ -48,11 +49,12 @@ class PipeFunc(PipeOperator[PipeFuncOutput]):
log.debug(f"Applying function '{self.function_name}'")
function = func_registry.get_required_function(self.function_name)
- if not callable(function):
- msg = f"Function '{self.function_name}' is not callable"
- raise TypeError(msg)
- func_output_object = await function(working_memory=working_memory)
+ if asyncio.iscoroutinefunction(function):
+ func_output_object = await function(working_memory=working_memory)
+ else:
+ func_output_object = await asyncio.to_thread(function, working_memory=working_memory)
+
the_content: StuffContent
if isinstance(func_output_object, StuffContent):
the_content = func_output_object
@@ -92,9 +94,6 @@ class PipeFunc(PipeOperator[PipeFuncOutput]):
log.debug(f"Dry run for PipeFunc '{self.function_name}'")
function = func_registry.get_required_function(self.function_name)
- if not callable(function):
- msg = f"Function '{self.function_name}' is not callable"
- raise TypeError(msg)
# Check that all needed inputs are present in working memory
needed_inputs = self.needed_inputs()
diff --git a/pipelex/pipe_operators/img_gen/pipe_img_gen.py b/pipelex/pipe_operators/img_gen/pipe_img_gen.py
index be9036289..d4d3684c8 100644
--- a/pipelex/pipe_operators/img_gen/pipe_img_gen.py
+++ b/pipelex/pipe_operators/img_gen/pipe_img_gen.py
@@ -138,44 +138,20 @@ class PipeImgGen(PipeOperator[PipeImgGenOutput]):
default_reaction = static_validation_config.default_reaction
reactions = static_validation_config.reactions
# check that we have either an img_gen_prompt passed as attribute or as a single text input
+ nb_inputs = self.inputs.nb_inputs
if self.img_gen_prompt:
- if self.inputs.items:
- msg = "img_gen_prompt_var_name must be None if img_gen_prompt is provided"
+ if nb_inputs > 0:
+ msg = "There must be no inputs if img_gen_prompt is provided"
raise PipeDefinitionError(msg)
# we're good with the prompt provided as attribute
return
- candidate_prompt_var_names: list[str] = []
- for input_name, requirement in self.inputs.items:
- log.debug(f"Validating input '{input_name}' with concept code '{requirement.concept.code}'")
- if concept_provider.is_compatible(
- tested_concept=requirement.concept,
- wanted_concept=ConceptFactory.make_native_concept(native_concept_data=NATIVE_CONCEPTS_DATA[NativeConceptEnum.TEXT]),
- ):
- self.img_gen_prompt_var_name = input_name
- candidate_prompt_var_names.append(input_name)
- else:
- inadequate_input_concept_error = StaticValidationError(
- error_type=StaticValidationErrorType.INADEQUATE_INPUT_CONCEPT,
- domain=self.domain,
- pipe_code=self.code,
- variable_names=[input_name],
- provided_concept_code=requirement.concept.code,
- explanation="Only a text input can be provided for image gen prompt",
- )
- match reactions.get(StaticValidationErrorType.INADEQUATE_INPUT_CONCEPT, default_reaction):
- case StaticValidationReaction.IGNORE:
- pass
- case StaticValidationReaction.LOG:
- log.error(inadequate_input_concept_error.desc())
- case StaticValidationReaction.RAISE:
- raise inadequate_input_concept_error
- if len(candidate_prompt_var_names) > 1:
+ if nb_inputs > 1:
too_many_candidate_inputs_error = StaticValidationError(
error_type=StaticValidationErrorType.TOO_MANY_CANDIDATE_INPUTS,
domain=self.domain,
pipe_code=self.code,
- variable_names=candidate_prompt_var_names,
+ variable_names=self.inputs.variables,
explanation="Only one text input can be provided for image gen prompt",
)
match reactions.get(StaticValidationErrorType.TOO_MANY_CANDIDATE_INPUTS, default_reaction):
@@ -185,7 +161,7 @@ class PipeImgGen(PipeOperator[PipeImgGenOutput]):
log.error(too_many_candidate_inputs_error.desc())
case StaticValidationReaction.RAISE:
raise too_many_candidate_inputs_error
- elif len(candidate_prompt_var_names) == 0:
+ elif nb_inputs < 1:
missing_input_var_error = StaticValidationError(
error_type=StaticValidationErrorType.MISSING_INPUT_VARIABLE,
domain=self.domain,
@@ -199,8 +175,32 @@ class PipeImgGen(PipeOperator[PipeImgGenOutput]):
log.error(missing_input_var_error.desc())
case StaticValidationReaction.RAISE:
raise missing_input_var_error
+
+ # We have confirmed right above that we have exactly one input
+ # get input_name, requirement from single item in inputs
+ input_name, requirement = self.inputs.items[0]
+ log.debug(f"Validating input '{input_name}' with concept code '{requirement.concept.code}'")
+ if concept_provider.is_compatible(
+ tested_concept=requirement.concept,
+ wanted_concept=ConceptFactory.make_native_concept(native_concept_data=NATIVE_CONCEPTS_DATA[NativeConceptEnum.TEXT]),
+ ):
+ self.img_gen_prompt_var_name = input_name
else:
- self.img_gen_prompt_var_name = candidate_prompt_var_names[0]
+ inadequate_input_concept_error = StaticValidationError(
+ error_type=StaticValidationErrorType.INADEQUATE_INPUT_CONCEPT,
+ domain=self.domain,
+ pipe_code=self.code,
+ variable_names=[input_name],
+ provided_concept_code=requirement.concept.code,
+ explanation="For PipeImgGen you must provide a text input or a concept that refines text",
+ )
+ match reactions.get(StaticValidationErrorType.INADEQUATE_INPUT_CONCEPT, default_reaction):
+ case StaticValidationReaction.IGNORE:
+ pass
+ case StaticValidationReaction.LOG:
+ log.error(inadequate_input_concept_error.desc())
+ case StaticValidationReaction.RAISE:
+ raise inadequate_input_concept_error
@override
async def _run_operator_pipe(
diff --git a/pipelex/pipe_operators/llm/pipe_llm.py b/pipelex/pipe_operators/llm/pipe_llm.py
index e7478f5fe..b6773d2f9 100644
--- a/pipelex/pipe_operators/llm/pipe_llm.py
+++ b/pipelex/pipe_operators/llm/pipe_llm.py
@@ -49,6 +49,7 @@ from pipelex.hub import (
from pipelex.pipe_operators.llm.pipe_llm_blueprint import StructuringMethod
from pipelex.pipe_operators.pipe_operator import PipeOperator
from pipelex.pipeline.job_metadata import JobMetadata
+from pipelex.tools.templating.jinja2_template_category import Jinja2TemplateCategory
from pipelex.tools.typing.structure_printer import StructurePrinter
from pipelex.types import Self
@@ -255,8 +256,9 @@ class PipeLLM(PipeOperator[PipeLLMOutput]):
base_multiplicity=self.output_multiplicity,
override_multiplicity=pipe_run_params.output_multiplicity,
)
+ log.debug(f"multiplicity_resolution: {multiplicity_resolution}")
applied_output_multiplicity = multiplicity_resolution.resolved_multiplicity
- is_multiple_output = multiplicity_resolution.enable_multiple_outputs
+ is_multiple_output = multiplicity_resolution.is_multiple_outputs_enabled
fixed_nb_output = multiplicity_resolution.specific_output_count
# Collect what LLM settings we have for this particular PipeLLM
@@ -299,32 +301,31 @@ class PipeLLM(PipeOperator[PipeLLMOutput]):
log.verbose(
f"is_with_preliminary_text: {is_with_preliminary_text} for pipe {self.code} because the structuring_method is {self.structuring_method}",
)
- # Append output structure prompt if needed
- output_structure_prompt: str | None = PipeLLM.get_output_structure_prompt(
- concept_string=pipe_run_params.dynamic_output_concept_code or output_concept.concept_string,
- is_with_preliminary_text=is_with_preliminary_text,
- )
llm_prompt_run_params = PipeRunParams.copy_by_injecting_multiplicity(
pipe_run_params=pipe_run_params,
applied_output_multiplicity=applied_output_multiplicity,
is_with_preliminary_text=is_with_preliminary_text,
)
+
# 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.
- llm_prompt_1 = await self.llm_prompt_spec.make_llm_prompt(
- output_concept_string=output_concept.concept_string,
- context_provider=working_memory,
- output_structure_prompt=output_structure_prompt,
- extra_params=llm_prompt_run_params.params,
- )
the_content: StuffContent
- if output_concept.structure_class_name == NativeConceptEnum.TEXT and not is_multiple_output:
- log.debug(f"PipeLLM generating a single text output: {self.class_name}_gen_text")
+ log.debug(f"output_concept.structure_class_name: {output_concept.structure_class_name}")
+ log.debug(f"TextContent.__class__.__name__: {TextContent.__class__.__name__}")
+ log.debug(f"is_multiple_output: {is_multiple_output}")
+ if output_concept.structure_class_name == "TextContent" and not is_multiple_output:
+ log.debug(f"PipeLLM generating a single text output: {self.__class__.__name__}_gen_text")
+ llm_prompt_1_for_text = await self.llm_prompt_spec.make_llm_prompt(
+ output_concept_string=output_concept.concept_string,
+ context_provider=working_memory,
+ output_structure_prompt=None,
+ extra_params=llm_prompt_run_params.params,
+ )
generated_text: str = await content_generator.make_llm_text(
job_metadata=job_metadata,
- llm_prompt_for_text=llm_prompt_1,
+ llm_prompt_for_text=llm_prompt_1_for_text,
llm_setting_main=llm_setting_main,
)
@@ -335,7 +336,7 @@ class PipeLLM(PipeOperator[PipeLLMOutput]):
if is_multiple_output:
log.debug(f"PipeLLM generating {fixed_nb_output} output(s)" if fixed_nb_output else "PipeLLM generating a list of output(s)")
else:
- log.debug("PipeLLM generating a single output")
+ log.debug(f"PipeLLM generating a single object output, class name: '{output_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.
@@ -388,6 +389,18 @@ class PipeLLM(PipeOperator[PipeLLMOutput]):
else:
llm_prompt_2_factory = None
+ output_structure_prompt: str | None = None
+ if get_config().cogt.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,
+ 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,
+ context_provider=working_memory,
+ output_structure_prompt=output_structure_prompt,
+ extra_params=llm_prompt_run_params.params,
+ )
the_content = await self._llm_gen_object_stuff_content(
job_metadata=job_metadata,
is_multiple_output=is_multiple_output,
@@ -395,7 +408,7 @@ class PipeLLM(PipeOperator[PipeLLMOutput]):
output_class_name=output_concept.structure_class_name,
llm_setting_main=llm_setting_main,
llm_setting_for_object=llm_setting_for_object,
- llm_prompt_1=llm_prompt_1,
+ llm_prompt_1=llm_prompt_1_for_object,
llm_prompt_2_factory=llm_prompt_2_factory,
content_generator=content_generator,
)
@@ -435,9 +448,9 @@ class PipeLLM(PipeOperator[PipeLLMOutput]):
if is_multiple_output:
# We're generating a list of (possibly multiple) objects
if fixed_nb_output:
- task_desc = f"{self.class_name}_gen_{fixed_nb_output}x{content_class.__class__.__name__}"
+ task_desc = f"{self.__class__.__name__}_gen_{fixed_nb_output}x{content_class.__class__.__name__}"
else:
- task_desc = f"{self.class_name}_gen_list_{content_class.__class__.__name__}"
+ task_desc = f"{self.__class__.__name__}_gen_list_{content_class.__class__.__name__}"
log.dev(task_desc)
generated_objects: list[StuffContent]
if llm_prompt_2_factory is not None:
@@ -470,7 +483,7 @@ class PipeLLM(PipeOperator[PipeLLMOutput]):
the_content = ListContent(items=generated_objects)
else:
# We're generating a single object
- task_desc = f"{self.class_name}_gen_single_{content_class.__name__}"
+ task_desc = f"{self.__class__.__name__}_gen_single_{content_class.__name__}"
log.verbose(task_desc)
if llm_prompt_2_factory is not None:
# We're generating a single object using preliminary text
@@ -517,40 +530,24 @@ class PipeLLM(PipeOperator[PipeLLMOutput]):
)
@staticmethod
- def get_output_structure_prompt(concept_string: str, is_with_preliminary_text: bool) -> str:
+ async def get_output_structure_prompt(concept_string: str, is_with_preliminary_text: bool) -> str | None:
concept = get_required_concept(concept_string=concept_string)
- class_name = concept.structure_class_name
- output_class = get_class_registry().get_class(class_name)
+ output_class = get_class_registry().get_class(concept.structure_class_name)
+ log.debug(f"get_output_structure_prompt for {concept_string} with {is_with_preliminary_text=}")
+ log.debug(f"output_class: {output_class}")
if not output_class:
- return ""
+ return None
class_structure = StructurePrinter().get_type_structure(tp=output_class, base_class=StuffContent)
if not class_structure:
- return ""
+ return None
class_structure_str = "\n".join(class_structure)
- # TODO: use proper prompt templating for this
- if is_with_preliminary_text:
- output_structure_prompt = f"""
-
----
-The instance we want to generate will be for the following class:
-{class_structure_str}
-
-Don't bother with JSON formatting, we'll do that as a second step.
-For now, just output markdown with the details of the instance.
-DO NOT create information.
-If some information is not present for an attribute, output the default value or None according to the attribute definition.
-"""
- else:
- output_structure_prompt = f"""
-
----
-The instance we want to generate will be for the following class:
-{class_structure_str}
-
-DO NOT create information.
-If some information is not present for an attribute, output the default value or None according to the attribute definition.
-"""
- return output_structure_prompt
+ return await get_content_generator().make_jinja2_text(
+ context={
+ "class_structure_str": class_structure_str,
+ },
+ template_category=Jinja2TemplateCategory.LLM_PROMPT,
+ jinja2_name="output_structure_prompt" if is_with_preliminary_text else "output_structure_prompt_no_preliminary_text",
+ )
diff --git a/pipelex/pipe_operators/llm/pipe_llm_blueprint.py b/pipelex/pipe_operators/llm/pipe_llm_blueprint.py
index a7c15ee59..b8457c2e0 100644
--- a/pipelex/pipe_operators/llm/pipe_llm_blueprint.py
+++ b/pipelex/pipe_operators/llm/pipe_llm_blueprint.py
@@ -17,6 +17,10 @@ class StructuringMethod(StrEnum):
class PipeLLMBlueprint(PipeBlueprint):
type: Literal["PipeLLM"] = "PipeLLM"
category: Literal["PipeOperator"] = "PipeOperator"
+
+ llm: LLMChoice | None = None
+ llm_to_structure: LLMChoice | None = None
+
system_prompt_template: str | None = None
system_prompt_template_name: str | None = None
system_prompt_name: str | None = None
@@ -27,9 +31,6 @@ class PipeLLMBlueprint(PipeBlueprint):
prompt_name: str | None = None
prompt: str | None = None
- llm: LLMChoice | None = None
- llm_to_structure: LLMChoice | None = None
-
structuring_method: StructuringMethod | None = None
prompt_template_to_structure: str | None = None
system_prompt_to_structure: str | None = None
@@ -38,11 +39,11 @@ class PipeLLMBlueprint(PipeBlueprint):
multiple_output: bool | None = None
@field_validator("nb_output", mode="after")
- @staticmethod
- def validate_nb_output(value: int | None = None) -> int | None:
- if value and value < 1:
- msg = "PipeLLMBlueprint nb_output must be greater than 0"
- raise PipeDefinitionError(msg)
+ @classmethod
+ def validate_nb_output(cls, value: int | None = None) -> int | None:
+ if value and value < 2:
+ msg = "PipeLLMBlueprint nb_output must be at least 2"
+ raise PipeDefinitionError(message=msg)
return value
@model_validator(mode="after")
diff --git a/pipelex/pipe_operators/ocr/pipe_ocr.py b/pipelex/pipe_operators/ocr/pipe_ocr.py
index 1d9838d8e..9b2c94c47 100644
--- a/pipelex/pipe_operators/ocr/pipe_ocr.py
+++ b/pipelex/pipe_operators/ocr/pipe_ocr.py
@@ -111,8 +111,6 @@ class PipeOcr(PipeOperator[PipeOcrOutput]):
# We have confirmed right above that we have exactly one input
# get input_name, requirement from single item in inputs
input_name, requirement = self.inputs.items[0]
- log.debug(f"{input_name=}")
- log.debug(f"{requirement=}")
log.debug(f"Validating input '{input_name}' with concept code '{requirement.concept.code}'")
if concept_provider.is_compatible(
tested_concept=requirement.concept,
@@ -133,7 +131,7 @@ class PipeOcr(PipeOperator[PipeOcrOutput]):
pipe_code=self.code,
variable_names=[input_name],
provided_concept_code=requirement.concept.code,
- explanation="For OCR you must provide either a pdf or an image or a concept that refines one of them",
+ explanation="For PipeOcr you must provide either a pdf or an image or a concept that refines one of them",
)
match reactions.get(StaticValidationErrorType.INADEQUATE_INPUT_CONCEPT, default_reaction):
case StaticValidationReaction.IGNORE:
diff --git a/pipelex/pipe_operators/pipe_operator.py b/pipelex/pipe_operators/pipe_operator.py
index d35a1f411..569cacb29 100644
--- a/pipelex/pipe_operators/pipe_operator.py
+++ b/pipelex/pipe_operators/pipe_operator.py
@@ -19,6 +19,10 @@ PipeOperatorOutputType = TypeVar("PipeOperatorOutputType", bound=PipeOutput)
class PipeOperator(PipeAbstract, Generic[PipeOperatorOutputType]):
category: Literal["PipeOperator"] = "PipeOperator"
+ @property
+ def class_name(self) -> str:
+ return self.__class__.__name__
+
@override
async def run_pipe(
self,
diff --git a/pipelex/pipe_works/pipe_dry.py b/pipelex/pipe_works/pipe_dry.py
index f5285278a..45136ff76 100644
--- a/pipelex/pipe_works/pipe_dry.py
+++ b/pipelex/pipe_works/pipe_dry.py
@@ -48,10 +48,11 @@ 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
- needed_inputs_for_factory = _convert_to_working_memory_format(needed_inputs_spec=pipe.needed_inputs())
-
- working_memory = WorkingMemoryFactory.make_for_dry_run(needed_inputs=needed_inputs_for_factory)
+ # TODO: fail and raise properly
try:
+ needed_inputs_for_factory = _convert_to_working_memory_format(needed_inputs_spec=pipe.needed_inputs())
+
+ working_memory = WorkingMemoryFactory.make_for_dry_run(needed_inputs=needed_inputs_for_factory)
pipe.validate_with_libraries()
await pipe.run_pipe(
job_metadata=JobMetadata(job_name=f"dry_run_{pipe.code}"),
@@ -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) -> list
needed_inputs_for_factory: list[TypedNamedInputRequirement] = []
class_registry = get_class_registry()
+ # TODO: fail and raise properly
for named_input_requirement in needed_inputs_spec.named_input_requirements:
try:
# Get the concept and its structure class
diff --git a/pipelex/pipelex.toml b/pipelex/pipelex.toml
index 352b8b794..9b3852e0d 100644
--- a/pipelex/pipelex.toml
+++ b/pipelex/pipelex.toml
@@ -6,8 +6,8 @@ observer_dir = "results/observer"
[pipelex.feature_config]
# WIP/Experimental feature flags
-is_pipeline_tracking_enabled = true
-is_activity_tracking_enabled = true
+is_pipeline_tracking_enabled = false
+is_activity_tracking_enabled = false
is_reporting_enabled = true
[pipelex.reporting_config]
@@ -87,9 +87,13 @@ is_auto_setup_preset_ocr = true
[cogt.llm_config]
default_max_images = 100
+is_structure_prompt_enabled = true
[cogt.llm_config.instructor_config]
is_openai_structured_output_enabled = false
+is_dump_kwargs_enabled = false
+is_dump_response_enabled = false
+is_dump_error_enabled = false
[cogt.llm_config.llm_job_config]
max_retries = 3
@@ -234,4 +238,3 @@ structure_field_ordering = ["type", "definition", "choices", "required"]
[pipelex.plx_config.pipes]
field_ordering = ["type", "definition", "inputs", "output"]
-
diff --git a/pipelex/plugins/anthropic/anthropic_llm_worker.py b/pipelex/plugins/anthropic/anthropic_llm_worker.py
index 77b67798b..bc533de71 100644
--- a/pipelex/plugins/anthropic/anthropic_llm_worker.py
+++ b/pipelex/plugins/anthropic/anthropic_llm_worker.py
@@ -10,9 +10,11 @@ from pipelex.cogt.llm.llm_job import LLMJob
from pipelex.cogt.llm.llm_worker_internal_abstract import LLMWorkerInternalAbstract
from pipelex.cogt.llm.structured_output import StructureMethod
from pipelex.cogt.model_backends.model_spec import InferenceModelSpec
+from pipelex.config import get_config
from pipelex.plugins.anthropic.anthropic_exceptions import AnthropicWorkerConfigurationError
from pipelex.plugins.anthropic.anthropic_factory import AnthropicFactory, AnthropicSdkVariant
from pipelex.reporting.reporting_protocol import ReportingProtocol
+from pipelex.tools.misc.instructor_utils import dump_error, dump_kwargs, dump_response
from pipelex.tools.typing.pydantic_utils import BaseModelTypeVar
from pipelex.types import StrEnum
@@ -75,6 +77,14 @@ class AnthropicLLMWorker(LLMWorkerInternalAbstract):
else:
self.instructor_for_objects = instructor.from_anthropic(client=sdk_instance)
+ instructor_config = get_config().cogt.llm_config.instructor_config
+ if instructor_config.is_dump_kwargs_enabled:
+ self.instructor_for_objects.on(hook_name="completion:kwargs", handler=dump_kwargs)
+ if instructor_config.is_dump_response_enabled:
+ self.instructor_for_objects.on(hook_name="completion:response", handler=dump_response)
+ if instructor_config.is_dump_error_enabled:
+ self.instructor_for_objects.on(hook_name="completion:error", handler=dump_error)
+
#########################################################
# Instance methods
#########################################################
diff --git a/pipelex/plugins/openai/openai_llm_worker.py b/pipelex/plugins/openai/openai_llm_worker.py
index f3e6cd9bb..6fd8b2b04 100644
--- a/pipelex/plugins/openai/openai_llm_worker.py
+++ b/pipelex/plugins/openai/openai_llm_worker.py
@@ -16,8 +16,10 @@ from pipelex.cogt.llm.llm_worker_internal_abstract import LLMWorkerInternalAbstr
from pipelex.cogt.llm.structured_output import StructureMethod
from pipelex.cogt.model_backends.model_constraints import ModelConstraints
from pipelex.cogt.model_backends.model_spec import InferenceModelSpec
+from pipelex.config import get_config
from pipelex.plugins.openai.openai_factory import OpenAIFactory
from pipelex.reporting.reporting_protocol import ReportingProtocol
+from pipelex.tools.misc.instructor_utils import dump_error, dump_kwargs, dump_response
from pipelex.tools.typing.pydantic_utils import BaseModelTypeVar
@@ -48,6 +50,14 @@ class OpenAILLMWorker(LLMWorkerInternalAbstract):
else:
self.instructor_for_objects = instructor.from_openai(client=sdk_instance)
+ instructor_config = get_config().cogt.llm_config.instructor_config
+ if instructor_config.is_dump_kwargs_enabled:
+ self.instructor_for_objects.on(hook_name="completion:kwargs", handler=dump_kwargs)
+ if instructor_config.is_dump_response_enabled:
+ self.instructor_for_objects.on(hook_name="completion:response", handler=dump_response)
+ if instructor_config.is_dump_error_enabled:
+ self.instructor_for_objects.on(hook_name="completion:error", handler=dump_error)
+
#########################################################
@override
def setup(self):
diff --git a/pipelex/tools/config/manager.py b/pipelex/tools/config/manager.py
index 97aefde57..578356e84 100644
--- a/pipelex/tools/config/manager.py
+++ b/pipelex/tools/config/manager.py
@@ -75,7 +75,6 @@ class ConfigManager:
"""
config_path = os.path.join(self.pipelex_config_dir, CONFIG_NAME)
- print(f"Getting local config from {config_path}")
return load_toml_from_path_if_exists(config_path) or {}
def load_inheritance_config(self, the_pipelex_config: dict[str, Any]):
diff --git a/pipelex/tools/func_registry.py b/pipelex/tools/func_registry.py
index 34b58e97e..7b7532417 100644
--- a/pipelex/tools/func_registry.py
+++ b/pipelex/tools/func_registry.py
@@ -1,7 +1,7 @@
import inspect
import logging
from collections.abc import Callable
-from typing import Any, TypeVar, get_type_hints
+from typing import Any, TypeVar, cast, get_type_hints
from pydantic import Field, PrivateAttr, RootModel
@@ -113,18 +113,25 @@ class FuncRegistry(RootModel[FuncRegistryDict]):
"""Checks if a function is in the registry by its name."""
return name in self.root
- def is_eligible_function(self, func: Callable[..., Any]) -> bool:
+ def is_eligible_function(self, func: Any) -> bool:
"""Checks if a function matches the criteria for PipeFunc registration:
+ - Must be callable
- Exactly 1 parameter named "working_memory" with type WorkingMemory
- Return type that is a subclass of StuffContent
"""
+ if not callable(func):
+ return False
+
+ the_function = cast("Callable[..., Any]", func)
+
try:
# Import here to avoid circular imports
+ # TODO: code-smell
from pipelex.core.memory.working_memory import WorkingMemory # noqa: PLC0415
from pipelex.core.stuffs.stuff_content import StuffContent # noqa: PLC0415
# Get function signature
- sig = inspect.signature(func)
+ sig = inspect.signature(the_function)
params = list(sig.parameters.values())
# Check parameter count and name
@@ -136,7 +143,7 @@ class FuncRegistry(RootModel[FuncRegistryDict]):
return False
# Get type hints
- type_hints = get_type_hints(func)
+ type_hints = get_type_hints(the_function)
# Check parameter type
if "working_memory" not in type_hints:
diff --git a/pipelex/tools/misc/context_provider_abstract.py b/pipelex/tools/misc/context_provider_abstract.py
index 1cff3ac83..23ba2c56e 100644
--- a/pipelex/tools/misc/context_provider_abstract.py
+++ b/pipelex/tools/misc/context_provider_abstract.py
@@ -20,5 +20,5 @@ class ContextProviderAbstract(ABC):
pass
@abstractmethod
- def generate_context(self) -> dict[str, Any]:
+ def generate_jinja2_context(self) -> dict[str, Any]:
pass
diff --git a/pipelex/tools/misc/instructor_utils.py b/pipelex/tools/misc/instructor_utils.py
new file mode 100644
index 000000000..b64340270
--- /dev/null
+++ b/pipelex/tools/misc/instructor_utils.py
@@ -0,0 +1,15 @@
+from typing import Any
+
+from pipelex import pretty_print
+
+
+def dump_kwargs(*_: Any, **kwargs: Any) -> None:
+ pretty_print(kwargs, title="Instructor about to send to LLM provider")
+
+
+def dump_response(response: Any) -> None:
+ pretty_print(response, title="Instructor response from LLM provider")
+
+
+def dump_error(error: Exception) -> None:
+ pretty_print(error, title="Instructor error from LLM provider")
diff --git a/pipelex/tools/misc/toml_utils.py b/pipelex/tools/misc/toml_utils.py
index 0fc407277..b01ea4515 100644
--- a/pipelex/tools/misc/toml_utils.py
+++ b/pipelex/tools/misc/toml_utils.py
@@ -7,83 +7,6 @@ import toml
from pipelex.tools.misc.file_utils import path_exists
-class TOMLValidationError(Exception):
- """Raised when TOML file has formatting issues that could cause problems."""
-
-
-def validate_toml_content(content: str, file_path: str | None = None) -> None:
- """Validate TOML content for common formatting issues."""
- lines = content.splitlines()
- issues: list[str] = []
-
- for line_num, line in enumerate(lines, 1):
- # Check for trailing whitespace
- if line.rstrip() != line:
- trailing_chars = line[len(line.rstrip()) :]
- trailing_repr = repr(trailing_chars)
- issues.append(f"Line {line_num}: Trailing whitespace detected: {trailing_repr}")
-
- # Check for trailing whitespace after triple quotes (common issue)
- if line.strip().endswith('"""') and line != line.rstrip():
- issues.append(f"Line {line_num}: Trailing whitespace after triple quotes - this can cause TOML parsing issues")
-
- # Check for mixed line endings
- has_crlf = "\r\n" in content
- content_without_crlf = content.replace("\r\n", "")
- has_standalone_lf = "\n" in content_without_crlf
- if has_crlf and has_standalone_lf:
- issues.append("Mixed line endings detected (both CRLF and LF)")
-
- if issues:
- error_msg = f"TOML formatting issues in '{file_path}':\n" + "\n".join(f" - {issue}" for issue in issues)
- raise TOMLValidationError(error_msg)
-
-
-def validate_toml_file(path: str) -> None:
- """Validate TOML file for formatting issues.
-
- Args:
- path: Path to the TOML file to validate
-
- Raises:
- TOMLValidationError: If formatting issues are detected
-
- """
- with open(path, encoding="utf-8") as file:
- content = file.read()
- validate_toml_content(content, path)
-
-
-def clean_trailing_whitespace(content: str) -> str:
- """Clean trailing whitespace from TOML content.
-
- This function:
- 1. Removes trailing whitespace from all lines
- 2. Ensures exactly one empty line at EOF (two newline characters)
- 3. If no empty line at EOF, removes trailing whitespace from last non-empty line
-
- Args:
- content: The TOML content to clean
-
- Returns:
- The cleaned TOML content with trailing whitespace removed and an empty line at EOF
-
- """
- # Split into lines and clean each line
- lines = [line.rstrip() for line in content.splitlines()]
-
- # Remove trailing empty lines
- while lines and not lines[-1]:
- lines.pop()
-
- # If we have lines and the last line has trailing whitespace, remove it
- if lines:
- lines[-1] = lines[-1].rstrip()
-
- # Join with newlines and ensure an empty line at EOF (two newlines)
- return "\n".join(lines) + "\n\n"
-
-
def load_toml_from_path(path: str) -> dict[str, Any]:
"""Load TOML from path.
@@ -101,15 +24,8 @@ def load_toml_from_path(path: str) -> dict[str, Any]:
with open(path, encoding="utf-8") as file:
content = file.read()
- cleaned_content = clean_trailing_whitespace(content)
-
- # If content changed, write it back
- if content != cleaned_content:
- with open(path, "w", encoding="utf-8") as file:
- file.write(cleaned_content)
-
# Parse TOML first
- return toml.loads(cleaned_content)
+ return toml.loads(content)
except toml.TomlDecodeError as exc:
msg = f"TOML parsing error in file '{path}': {exc}"
raise toml.TomlDecodeError(msg, exc.doc, exc.pos) from exc
diff --git a/pipelex/tools/templating/jinja2_filters.py b/pipelex/tools/templating/jinja2_filters.py
index c798c5293..da0341de1 100644
--- a/pipelex/tools/templating/jinja2_filters.py
+++ b/pipelex/tools/templating/jinja2_filters.py
@@ -12,7 +12,7 @@ from pipelex.types import StrEnum
# Jinja2 filters
########################################################################################
-ALLOWED_FILTERS = ["tag", "format"]
+ALLOWED_FILTERS = ["tag", "format", "default"]
# Filter to format some Stuff or any object with the appropriate text formatting methods
diff --git a/pipelex/tools/templating/jinja2_template_category.py b/pipelex/tools/templating/jinja2_template_category.py
index cae802315..3c8c09780 100644
--- a/pipelex/tools/templating/jinja2_template_category.py
+++ b/pipelex/tools/templating/jinja2_template_category.py
@@ -9,6 +9,7 @@ from pipelex.tools.templating.templating_models import TextFormat
from pipelex.types import StrEnum
+# TODO: add more categories
class Jinja2TemplateCategory(StrEnum):
HTML = "html"
MARKDOWN = "markdown"
diff --git a/pipelex/tools/templating/template_library.py b/pipelex/tools/templating/template_library.py
index 82132d484..990d38063 100644
--- a/pipelex/tools/templating/template_library.py
+++ b/pipelex/tools/templating/template_library.py
@@ -1,3 +1,4 @@
+from pathlib import Path
from typing import Any, ClassVar, cast
from jinja2 import TemplateSyntaxError
@@ -7,6 +8,7 @@ from typing_extensions import override
from pipelex import log
from pipelex.libraries.library_config import LibraryConfig
from pipelex.tools.exceptions import ToolException
+from pipelex.tools.misc.file_utils import find_files_in_dir
from pipelex.tools.misc.toml_utils import load_toml_from_path
from pipelex.tools.templating.jinja2_parsing import check_jinja2_parsing
from pipelex.tools.templating.jinja2_template_category import Jinja2TemplateCategory
@@ -32,9 +34,10 @@ class TemplateLibrary(TemplateProviderAbstract, RootModel[TemplateLibraryRoot]):
@override
def setup(self) -> None:
- template_toml_paths = self.library_config.get_templates_paths()
+ templates_dir = Path(__file__).parent / "templates"
+ template_toml_paths = find_files_in_dir(dir_path=str(templates_dir), pattern="*.toml", is_recursive=True)
for template_toml_path in template_toml_paths:
- self._load_from_toml(toml_path=template_toml_path)
+ self._load_from_toml(toml_path=str(template_toml_path))
self.validate_templates(template_category=Jinja2TemplateCategory.LLM_PROMPT)
@override
diff --git a/pipelex/tools/templating/template_preprocessor.py b/pipelex/tools/templating/template_preprocessor.py
index 7cfdadc5b..1db627b24 100644
--- a/pipelex/tools/templating/template_preprocessor.py
+++ b/pipelex/tools/templating/template_preprocessor.py
@@ -1,38 +1,34 @@
import re
from re import Match
-from pipelex.tools.templating.jinja2_errors import Jinja2TemplateError
-from pipelex.tools.templating.jinja2_filters import ALLOWED_FILTERS
+# def _detect_non_existent_filters(template_str: str) -> None:
+# """Check a template string for non-existent Jinja2 filters.
+# Args:
+# template_str: The template string to check
-def _detect_non_existent_filters(template_str: str) -> None:
- """Check a template string for non-existent Jinja2 filters.
+# Raises:
+# Jinja2TemplateError: If any non-allowed filters are found
- Args:
- template_str: The template string to check
+# """
+# # Pattern to match Jinja2 filter syntax: {{ variable|filter() }} or {{ variable|filter(param) }}
+# # This handles:
+# # - {{ variable|filter }}
+# # - {{ variable|filter() }}
+# # - {{ variable|filter(param) }}
+# # - {{ variable|filter(param1, param2) }}
+# filter_pattern = r"\{\{\s*[^|}]+\|\s*([a-zA-Z0-9_]+)(?:\([^)]*\))?\s*\}\}"
+# matches = re.finditer(filter_pattern, template_str)
- Raises:
- Jinja2TemplateError: If any non-allowed filters are found
+# invalid_filters: list[str] = []
+# for match in matches:
+# filter_name = match.group(1)
+# if filter_name not in ALLOWED_FILTERS:
+# invalid_filters.append(filter_name)
- """
- # Pattern to match Jinja2 filter syntax: {{ variable|filter() }} or {{ variable|filter(param) }}
- # This handles:
- # - {{ variable|filter }}
- # - {{ variable|filter() }}
- # - {{ variable|filter(param) }}
- # - {{ variable|filter(param1, param2) }}
- filter_pattern = r"\{\{\s*[^|}]+\|\s*([a-zA-Z0-9_]+)(?:\([^)]*\))?\s*\}\}"
- matches = re.finditer(filter_pattern, template_str)
-
- invalid_filters: list[str] = []
- for match in matches:
- filter_name = match.group(1)
- if filter_name not in ALLOWED_FILTERS:
- invalid_filters.append(filter_name)
-
- if invalid_filters:
- msg = f"Invalid Jinja2 filters found: {invalid_filters}. Only the following filters are allowed: {ALLOWED_FILTERS}"
- raise Jinja2TemplateError(msg)
+# if invalid_filters:
+# msg = f"Invalid Jinja2 filters found: {invalid_filters}. Only the following filters are allowed: {ALLOWED_FILTERS}"
+# raise Jinja2TemplateError(msg)
# Handle @variable patterns
@@ -69,7 +65,7 @@ def preprocess_template(template: str) -> str:
"""Preprocess a template string to interpret our syntax patterns and convert them to Jinja2 syntax.
Also, detect the use of non-existent filters.
"""
- _detect_non_existent_filters(template_str=template)
+ # _detect_non_existent_filters(template_str=template)
processed_template = template
changes_made = False
diff --git a/pipelex/tools/templating/templates/__init__.py b/pipelex/tools/templating/templates/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/pipelex/tools/templating/templates/base_templates.toml b/pipelex/tools/templating/templates/base_templates.toml
new file mode 100644
index 000000000..fb1a8d026
--- /dev/null
+++ b/pipelex/tools/templating/templates/base_templates.toml
@@ -0,0 +1,34 @@
+[generic_prompts]
+structure_from_preliminary_text_system = "You are a data modeling expert specialized in extracting structure from text."
+# TODO: Should be a proper jinja2
+structure_from_preliminary_text_user = """
+Your job is to extract and structure information from a text.
+Here is the text:
+{preliminary_text}
+
+Now generate the JSON in the required format.
+Do not create information that is not in the text.
+"""
+
+output_structure_prompt = """
+---
+The instance we want to generate will be for the following class:
+{{ class_structure_str }}
+
+Don't bother with JSON formatting, we'll do that as a second step.
+For now, just output markdown with the details of the instance.
+DO NOT create information.
+If some information is not present for an attribute, output the default value or None according to the attribute definition.
+"""
+
+output_structure_prompt_no_preliminary_text = """
+---
+The instance we want to generate will be for the following class:
+{{ class_structure_str }}
+
+DO NOT create information.
+If some information is not present for an attribute, output the default value or None according to the attribute definition.
+"""
+
+[test_prompts]
+jinja2_test_template = "I want a {{ place_holder }} t-shirt."
diff --git a/pipelex/tools/typing/pydantic_utils.py b/pipelex/tools/typing/pydantic_utils.py
index 8190dc636..411f40150 100644
--- a/pipelex/tools/typing/pydantic_utils.py
+++ b/pipelex/tools/typing/pydantic_utils.py
@@ -40,6 +40,14 @@ def format_pydantic_validation_error(exc: ValidationError) -> str:
enum_errors = [
f"{'.'.join(map(str, err['loc']))}: invalid enum value '{err.get('input', 'unknown')}'" for err in exc.errors() if err["type"] == "enum"
]
+ union_tag_errors: list[str] = []
+ for err in exc.errors():
+ if err["type"] == "union_tag_not_found":
+ field_path = ".".join(map(str, err["loc"]))
+ # Extract discriminator field name from context
+ discriminator = err.get("ctx", {}).get("discriminator", "type")
+ union_tag_errors.append(f"{field_path}: missing required discriminator field '{discriminator}'")
+
model_type_errors: list[str] = []
for err in exc.errors():
if err["type"] == "model_type":
@@ -61,11 +69,13 @@ def format_pydantic_validation_error(exc: ValidationError) -> str:
error_msg += f"\nValue errors: {value_errors}"
if enum_errors:
error_msg += f"\nEnum errors: {enum_errors}"
+ if union_tag_errors:
+ error_msg += f"\nUnion discriminator errors: {union_tag_errors}"
if model_type_errors:
error_msg += f"\nModel type errors: {model_type_errors}"
# If none of the specific error types were found, add the raw error messages
- if not any([missing_fields, extra_fields, type_errors, value_errors, enum_errors, model_type_errors]):
+ if not any([missing_fields, extra_fields, type_errors, value_errors, enum_errors, union_tag_errors, model_type_errors]):
error_msg += "\nOther validation errors:"
for err in exc.errors():
error_msg += f"\n{'.'.join(map(str, err['loc']))}: {err['type']}: {err['msg']}"
diff --git a/pyproject.toml b/pyproject.toml
index f4d38d4c5..090ecb1c4 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -202,7 +202,7 @@ reportUnusedFunction = "error"
reportUnusedImport = "none"
reportUnusedVariable = "error"
reportWildcardImportFromLibrary = "error"
-reportUnusedParameter = "error"
+reportUnusedParameter = "information"
strictDictionaryInference = true
strictListInference = true
strictParameterNoneValue = true
diff --git a/tests/data/tools_data/problematic_test_cases.toml b/tests/data/tools_data/problematic_test_cases.toml
deleted file mode 100644
index 9b2977c95..000000000
--- a/tests/data/tools_data/problematic_test_cases.toml
+++ /dev/null
@@ -1,23 +0,0 @@
-domain = "test_validation_failures"
-definition = "Test cases with various validation issues"
-
-[concept]
-TestInput = "A test input concept"
-
-[pipe]
-[pipe.test_pipe_with_issues]
-type = "PipeLLM"
-definition = "Test pipe with trailing whitespace issues"
-inputs = { input_data = "TestInput" }
-output = "native.Text"
-prompt_template = """
-This template has trailing whitespace after closing quotes
-"""
-
-[pipe.another_problematic_pipe]
-type = "PipeLLM"
-definition = "Another pipe with issues"
-output = "native.Text"
-prompt_template = """
-Multiple issues here
-"""
diff --git a/tests/integration/pipelex/cogt/test_llm_job_async_factory.py b/tests/integration/pipelex/cogt/test_llm_job_async_factory.py
deleted file mode 100644
index 0b1ed2920..000000000
--- a/tests/integration/pipelex/cogt/test_llm_job_async_factory.py
+++ /dev/null
@@ -1,50 +0,0 @@
-import random
-
-import pytest
-
-from pipelex import pretty_print
-from pipelex.cogt.llm.llm_job import LLMJobParams
-from pipelex.cogt.llm.llm_job_factory import LLMJobFactory
-from pipelex.cogt.llm.llm_prompt_template import LLMPromptTemplate
-from pipelex.hub import get_llm_worker
-from tests.integration.pipelex.cogt.test_data import LLMTestConstants
-
-
[email protected](loop_scope="class")
-class TestAsyncLLMJobFactory:
- async def test_llm_job_using_generic_prompt_factory(self):
- llm_prompt_template = LLMPromptTemplate.from_template_contents(user_text=LLMTestConstants.PROMPT_TEMPLATE_TEXT)
- random_color = random.choice(LLMTestConstants.PROMPT_COLOR_EXAMPLES)
- llm_job = await LLMJobFactory.make_llm_job_from_prompt_factory(
- llm_prompt_factory=llm_prompt_template,
- llm_prompt_arguments={"color": random_color},
- llm_job_params=LLMJobParams(temperature=0.5, max_tokens=50, seed=None),
- )
- assert llm_job
- pretty_print(llm_job)
-
- async def test_llm_job_using_prompt_template(self):
- llm_prompt_template = LLMPromptTemplate.from_template_contents(user_text=LLMTestConstants.PROMPT_TEMPLATE_TEXT)
- random_color = random.choice(LLMTestConstants.PROMPT_COLOR_EXAMPLES)
- llm_job = await LLMJobFactory.make_llm_job_from_prompt_template(
- llm_prompt_template=llm_prompt_template,
- llm_prompt_arguments={"color": random_color},
- llm_job_params=LLMJobParams(temperature=0.5, max_tokens=50, seed=None),
- )
- assert llm_job
- pretty_print(llm_job)
-
- @pytest.mark.llm
- @pytest.mark.inference
- async def test_llm_job_and_gen_text(self, llm_handle: str):
- llm_worker = get_llm_worker(llm_handle=llm_handle)
- llm_prompt_template = LLMPromptTemplate.from_template_contents(user_text=LLMTestConstants.PROMPT_TEMPLATE_TEXT)
- random_color = random.choice(LLMTestConstants.PROMPT_COLOR_EXAMPLES)
- llm_job = await LLMJobFactory.make_llm_job_from_prompt_template(
- llm_prompt_template=llm_prompt_template,
- llm_prompt_arguments={"color": random_color},
- llm_job_params=LLMJobParams(temperature=0.5, max_tokens=50, seed=None),
- )
- generated_text = await llm_worker.gen_text(llm_job=llm_job)
- assert generated_text
- pretty_print(generated_text)
diff --git a/tests/integration/pipelex/conftest.py b/tests/integration/pipelex/conftest.py
index 898cb0107..7ad270cd7 100644
--- a/tests/integration/pipelex/conftest.py
+++ b/tests/integration/pipelex/conftest.py
@@ -51,7 +51,7 @@ def llm_preset_id(request: pytest.FixtureRequest) -> str:
# "gpt-4o-mini",
# "gpt-5-mini",
# "gpt-5-chat",
- # "claude-4-sonnet",
+ "claude-4-sonnet",
# "claude-4.1-opus",
# "claude-3.5-sonnet",
# "claude-3.5-sonnet-v2"
@@ -59,7 +59,7 @@ def llm_preset_id(request: pytest.FixtureRequest) -> str:
# "grok-3",
# "grok-3-mini",
# "base-claude",
- "gemini-2.5-flash-lite",
+ # "gemini-2.5-flash-lite",
# "gemini-2.5-flash",
# "gemini-2.5-pro",
],
diff --git a/tests/integration/pipelex/libraries/pipelines/builder/__init__.py b/tests/integration/pipelex/libraries/pipelines/builder/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/tests/integration/pipelex/libraries/pipelines/builder/concept/__init__.py b/tests/integration/pipelex/libraries/pipelines/builder/concept/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/tests/integration/pipelex/libraries/pipelines/builder/concept/integration_test_data.py b/tests/integration/pipelex/libraries/pipelines/builder/concept/integration_test_data.py
new file mode 100644
index 000000000..84df0b09d
--- /dev/null
+++ b/tests/integration/pipelex/libraries/pipelines/builder/concept/integration_test_data.py
@@ -0,0 +1,123 @@
+from typing import ClassVar
+
+
+class ConceptSpecGenerationTestCases:
+ """Test cases for LLM-based ConceptSpec generation."""
+
+ # Test case: Simple concept without structure or refines
+ SIMPLE_CONCEPT_PROMPT = """
+Generate a concept specification for a "BlogPost" concept.
+
+Requirements:
+- the_concept_code: BlogPost
+- definition: A blog post with title, content, and publication date
+- structure: None (leave empty)
+- refines: None (leave empty)
+"""
+
+ # Test case: Concept that refines a native concept
+ REFINES_TEXT_PROMPT = """
+Generate a concept specification for a "ProductDescription" concept.
+
+Requirements:
+- the_concept_code: ProductDescription
+- definition: A detailed description of a product for e-commerce
+- refines: Text (this concept refines the native Text concept)
+- structure: None (leave empty because we're using refines)
+"""
+
+ # Test case: Concept with simple structure
+ SIMPLE_STRUCTURE_PROMPT = """
+Generate a concept specification for a "Person" concept with a simple structure.
+
+Requirements:
+- the_concept_code: Person
+- definition: A person with basic information
+- structure: A dictionary with these fields:
+ - name: (type: text, definition: "The person's full name", required: true)
+ - age: (type: integer, definition: "The person's age", required: true)
+- refines: None (leave empty)
+"""
+
+ # Test case: Concept with complex structure
+ COMPLEX_STRUCTURE_PROMPT = """
+Generate a concept specification for a "Product" concept with a detailed structure.
+
+Requirements:
+- the_concept_code: Product
+- definition: A product in an e-commerce system
+- structure: A dictionary with these fields:
+ - name: (type: text, definition: "Product name", required: true)
+ - description: (type: text, definition: "Product description", required: true)
+ - price: (type: number, definition: "Product price in dollars", required: true)
+ - stock_quantity: (type: integer, definition: "Number of items in stock", required: false, default_value: 0)
+ - is_available: (type: boolean, definition: "Whether the product is currently available", required: false, default_value: true)
+- refines: None (leave empty)
+"""
+
+ # Test case: Concept with optional fields and defaults
+ OPTIONAL_FIELDS_PROMPT = """
+Generate a concept specification for a "UserProfile" concept.
+
+Requirements:
+- the_concept_code: UserProfile
+- definition: A user profile with optional settings
+- structure: A dictionary with these fields:
+ - username: (type: text, definition: "User's username", required: true)
+ - email: (type: text, definition: "User's email address", required: true)
+ - bio: (type: text, definition: "User biography", required: false, default_value: "")
+ - notification_enabled: (type: boolean, definition: "Whether notifications are enabled", required: false, default_value: true)
+ - login_count: (type: integer, definition: "Number of times user has logged in", required: false, default_value: 0)
+- refines: None (leave empty)
+"""
+
+ # Test case: Concept with snake_case code (tests conversion)
+ SNAKE_CASE_CONCEPT_PROMPT = """
+Generate a concept specification for a "customer_order" concept.
+
+Requirements:
+- the_concept_code: customer_order
+- definition: An order placed by a customer
+- structure: A dictionary with these fields:
+ - order_number: (type: text, definition: "Unique order identifier", required: true)
+ - total_amount: (type: number, definition: "Total order amount", required: true)
+ - is_paid: (type: boolean, definition: "Payment status", required: false, default_value: false)
+- refines: None (leave empty)
+"""
+
+ # Test case: Concept refining Image
+ REFINES_IMAGE_PROMPT = """
+Generate a concept specification for a "ProductPhoto" concept.
+
+Requirements:
+- the_concept_code: ProductPhoto
+- definition: A photograph of a product for display in catalog
+- refines: Image (this concept refines the native Image concept)
+- structure: None (leave empty because we're using refines)
+"""
+
+ # Test case: Concept with date field
+ DATE_FIELD_PROMPT = """
+Generate a concept specification for an "Event" concept with a date field.
+
+Requirements:
+- the_concept_code: Event
+- definition: An event with scheduling information
+- structure: A dictionary with these fields:
+ - title: (type: text, definition: "Event title", required: true)
+ - description: (type: text, definition: "Event description", required: true)
+ - start_date: (type: date, definition: "Event start date and time", required: true)
+ - is_public: (type: boolean, definition: "Whether the event is public", required: false, default_value: true)
+- refines: None (leave empty)
+"""
+
+ TEST_CASES: ClassVar[list[tuple[str, str]]] = [
+ # ("simple_concept", SIMPLE_CONCEPT_PROMPT),
+ # ("refines_text", REFINES_TEXT_PROMPT),
+ # ("simple_structure", SIMPLE_STRUCTURE_PROMPT),
+ # ("complex_structure", COMPLEX_STRUCTURE_PROMPT),
+ # ("optional_fields", OPTIONAL_FIELDS_PROMPT),
+ ("snake_case_concept", SNAKE_CASE_CONCEPT_PROMPT),
+ # ("refines_image", REFINES_IMAGE_PROMPT),
+ # ("date_field", DATE_FIELD_PROMPT),
+ ]
diff --git a/tests/integration/pipelex/libraries/pipelines/builder/concept/test_concept_spec_generation.py b/tests/integration/pipelex/libraries/pipelines/builder/concept/test_concept_spec_generation.py
new file mode 100644
index 000000000..6c8b7f262
--- /dev/null
+++ b/tests/integration/pipelex/libraries/pipelines/builder/concept/test_concept_spec_generation.py
@@ -0,0 +1,69 @@
+import pytest
+
+from pipelex import log, pretty_print
+from pipelex.cogt.llm.llm_job_components import LLMJobParams
+from pipelex.cogt.llm.llm_job_factory import LLMJobFactory
+from pipelex.hub import get_llm_worker
+from pipelex.libraries.pipelines.builder.concept.concept_spec import ConceptSpec
+
+from tests.integration.pipelex.libraries.pipelines.builder.concept.integration_test_data import ConceptSpecGenerationTestCases
+
+
[email protected](loop_scope="class")
+class TestConceptSpecGeneration:
+ """Integration tests for generating ConceptSpec objects using LLM.
+
+ These tests verify that LLMs can generate valid ConceptSpec objects
+ from natural language prompts describing various concept shapes.
+ """
+
+ @pytest.mark.parametrize("topic,user_prompt", ConceptSpecGenerationTestCases.TEST_CASES)
+ async def test_generate_concept_spec(
+ self,
+ llm_job_params: LLMJobParams,
+ llm_handle: str,
+ topic: str,
+ user_prompt: str,
+ ):
+ """Test generating a ConceptSpec using LLM from a natural language prompt.
+
+ Args:
+ llm_job_params: LLM job parameters from fixture
+ llm_handle: LLM handle from fixture
+ topic: Test case topic/name
+ user_prompt: Natural language prompt describing the concept
+ """
+ log.info(f"Testing {topic} with llm_handle '{llm_handle}'")
+
+ # Get the LLM worker
+ llm_worker = get_llm_worker(llm_handle=llm_handle)
+
+ # Skip if object generation is not supported
+ if not llm_worker.is_gen_object_supported:
+ pytest.skip(f"LLM worker '{llm_worker.desc}' does not support object generation")
+
+ log.info(f"Using llm_worker: {llm_worker.desc}")
+
+ # Create the LLM job with the prompt
+ llm_job = LLMJobFactory.make_llm_job_from_prompt_contents(
+ system_text="You are an expert at generating concept specifications for a data modeling system.",
+ user_text=user_prompt,
+ llm_job_params=llm_job_params,
+ )
+
+ # Generate the ConceptSpec object
+ generated_concept_spec = await llm_worker.gen_object(llm_job=llm_job, schema=ConceptSpec)
+
+ # Display the result
+ pretty_print(generated_concept_spec, title=f"Generated ConceptSpec for '{topic}' using {llm_handle}")
+
+ # Basic validation: if we got here without exceptions, the ConceptSpec was created successfully
+ # The Pydantic validation and field validators have already run
+ assert generated_concept_spec is not None
+ assert isinstance(generated_concept_spec, ConceptSpec)
+ assert generated_concept_spec.the_concept_code
+ assert generated_concept_spec.definition
+
+ log.info(f"✓ Successfully generated ConceptSpec for '{topic}': {generated_concept_spec.the_concept_code}")
diff --git a/tests/test_pipelines/pipe_controllers/pipe_sequence/pipe_sequence_2.plx b/tests/test_pipelines/pipe_controllers/pipe_sequence/pipe_sequence_2.plx
index 689564787..60f3465a8 100644
--- a/tests/test_pipelines/pipe_controllers/pipe_sequence/pipe_sequence_2.plx
+++ b/tests/test_pipelines/pipe_controllers/pipe_sequence/pipe_sequence_2.plx
@@ -25,7 +25,7 @@ type = "PipeLLM"
definition = "Extract individual reviews from document"
inputs = { document = "Document" }
output = "CustomerReview"
-nb_output = 1
+multiple_output = true
llm = "llm_for_testing_gen_text"
prompt_template = """
Extract each individual customer review from this document as separate items:
diff --git a/tests/unit/pipelex/core/concepts/test_structured_output_generator.py b/tests/unit/pipelex/core/concepts/test_structured_output_generator.py
index 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_print
from pipelex.core.concepts.concept_blueprint import ConceptStructureBlueprint, ConceptStructureBlueprintFieldType
from 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 StructuredContent
class 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)
diff --git a/tests/unit/pipelex/core/pipes/data.py b/tests/unit/pipelex/core/pipes/data.py
index 145267a20..85e6ce250 100644
--- a/tests/unit/pipelex/core/pipes/data.py
+++ b/tests/unit/pipelex/core/pipes/data.py
@@ -34,128 +34,128 @@ OUTPUT_MULTIPLICITY_TO_APPLY_TEST_CASES: list[
(
None,
None,
- OutputMultiplicityResolution(resolved_multiplicity=None, enable_multiple_outputs=False, specific_output_count=None),
+ OutputMultiplicityResolution(resolved_multiplicity=None, is_multiple_outputs_enabled=False, specific_output_count=None),
"base=None, override=None",
),
(
True,
None,
- OutputMultiplicityResolution(resolved_multiplicity=True, enable_multiple_outputs=True, specific_output_count=None),
+ OutputMultiplicityResolution(resolved_multiplicity=True, is_multiple_outputs_enabled=True, specific_output_count=None),
"base=True, override=None",
),
(
False,
None,
- OutputMultiplicityResolution(resolved_multiplicity=False, enable_multiple_outputs=False, specific_output_count=None),
+ OutputMultiplicityResolution(resolved_multiplicity=False, is_multiple_outputs_enabled=False, specific_output_count=None),
"base=False, override=None",
),
- (3, None, OutputMultiplicityResolution(resolved_multiplicity=3, enable_multiple_outputs=True, specific_output_count=3), "base=3, override=None"),
- (5, None, OutputMultiplicityResolution(resolved_multiplicity=5, enable_multiple_outputs=True, specific_output_count=5), "base=5, override=None"),
+ (3, None, OutputMultiplicityResolution(resolved_multiplicity=3, is_multiple_outputs_enabled=True, specific_output_count=3), "base=3, override=None"),
+ (5, None, OutputMultiplicityResolution(resolved_multiplicity=5, is_multiple_outputs_enabled=True, specific_output_count=5), "base=5, override=None"),
# Override is False - force single output regardless of base
(
None,
False,
- OutputMultiplicityResolution(resolved_multiplicity=False, enable_multiple_outputs=False, specific_output_count=None),
+ OutputMultiplicityResolution(resolved_multiplicity=False, is_multiple_outputs_enabled=False, specific_output_count=None),
"base=None, override=False",
),
(
True,
False,
- OutputMultiplicityResolution(resolved_multiplicity=False, enable_multiple_outputs=False, specific_output_count=None),
+ OutputMultiplicityResolution(resolved_multiplicity=False, is_multiple_outputs_enabled=False, specific_output_count=None),
"base=True, override=False",
),
(
False,
False,
- OutputMultiplicityResolution(resolved_multiplicity=False, enable_multiple_outputs=False, specific_output_count=None),
+ OutputMultiplicityResolution(resolved_multiplicity=False, is_multiple_outputs_enabled=False, specific_output_count=None),
"base=False, override=False",
),
(
3,
False,
- OutputMultiplicityResolution(resolved_multiplicity=False, enable_multiple_outputs=False, specific_output_count=None),
+ OutputMultiplicityResolution(resolved_multiplicity=False, is_multiple_outputs_enabled=False, specific_output_count=None),
"base=3, override=False",
),
(
10,
False,
- OutputMultiplicityResolution(resolved_multiplicity=False, enable_multiple_outputs=False, specific_output_count=None),
+ OutputMultiplicityResolution(resolved_multiplicity=False, is_multiple_outputs_enabled=False, specific_output_count=None),
"base=10, override=False",
),
# Override is True - enable multiple outputs
(
None,
True,
- OutputMultiplicityResolution(resolved_multiplicity=None, enable_multiple_outputs=True, specific_output_count=None),
+ OutputMultiplicityResolution(resolved_multiplicity=None, is_multiple_outputs_enabled=True, specific_output_count=None),
"base=None, override=True",
),
(
True,
True,
- OutputMultiplicityResolution(resolved_multiplicity=True, enable_multiple_outputs=True, specific_output_count=None),
+ OutputMultiplicityResolution(resolved_multiplicity=True, is_multiple_outputs_enabled=True, specific_output_count=None),
"base=True, override=True",
),
(
False,
True,
- OutputMultiplicityResolution(resolved_multiplicity=True, enable_multiple_outputs=True, specific_output_count=None),
+ OutputMultiplicityResolution(resolved_multiplicity=True, is_multiple_outputs_enabled=True, specific_output_count=None),
"base=False, override=True",
),
(
3,
True,
- OutputMultiplicityResolution(resolved_multiplicity=3, enable_multiple_outputs=True, specific_output_count=3),
+ OutputMultiplicityResolution(resolved_multiplicity=3, is_multiple_outputs_enabled=True, specific_output_count=3),
"base=3, override=True - preserve base count",
),
(
7,
True,
- OutputMultiplicityResolution(resolved_multiplicity=7, enable_multiple_outputs=True, specific_output_count=7),
+ OutputMultiplicityResolution(resolved_multiplicity=7, is_multiple_outputs_enabled=True, specific_output_count=7),
"base=7, override=True - preserve base count",
),
# Override is int - use override count, enable multiple outputs
- (None, 2, OutputMultiplicityResolution(resolved_multiplicity=2, enable_multiple_outputs=True, specific_output_count=2), "base=None, override=2"),
- (True, 4, OutputMultiplicityResolution(resolved_multiplicity=4, enable_multiple_outputs=True, specific_output_count=4), "base=True, override=4"),
+ (None, 2, OutputMultiplicityResolution(resolved_multiplicity=2, is_multiple_outputs_enabled=True, specific_output_count=2), "base=None, override=2"),
+ (True, 4, OutputMultiplicityResolution(resolved_multiplicity=4, is_multiple_outputs_enabled=True, specific_output_count=4), "base=True, override=4"),
(
False,
6,
- OutputMultiplicityResolution(resolved_multiplicity=6, enable_multiple_outputs=True, specific_output_count=6),
+ OutputMultiplicityResolution(resolved_multiplicity=6, is_multiple_outputs_enabled=True, specific_output_count=6),
"base=False, override=6",
),
(
3,
8,
- OutputMultiplicityResolution(resolved_multiplicity=8, enable_multiple_outputs=True, specific_output_count=8),
+ OutputMultiplicityResolution(resolved_multiplicity=8, is_multiple_outputs_enabled=True, specific_output_count=8),
"base=3, override=8 - override takes precedence",
),
(
5,
1,
- OutputMultiplicityResolution(resolved_multiplicity=1, enable_multiple_outputs=True, specific_output_count=1),
+ OutputMultiplicityResolution(resolved_multiplicity=1, is_multiple_outputs_enabled=True, specific_output_count=1),
"base=5, override=1 - override takes precedence",
),
# Edge cases with negative numbers
(
-1,
None,
- OutputMultiplicityResolution(resolved_multiplicity=-1, enable_multiple_outputs=True, specific_output_count=-1),
+ OutputMultiplicityResolution(resolved_multiplicity=-1, is_multiple_outputs_enabled=True, specific_output_count=-1),
"base=-1, override=None",
),
- (3, -2, OutputMultiplicityResolution(resolved_multiplicity=-2, enable_multiple_outputs=True, specific_output_count=-2), "base=3, override=-2"),
+ (3, -2, OutputMultiplicityResolution(resolved_multiplicity=-2, is_multiple_outputs_enabled=True, specific_output_count=-2), "base=3, override=-2"),
# Edge cases with zero
- (0, None, OutputMultiplicityResolution(resolved_multiplicity=0, enable_multiple_outputs=True, specific_output_count=0), "base=0, override=None"),
- (True, 0, OutputMultiplicityResolution(resolved_multiplicity=0, enable_multiple_outputs=True, specific_output_count=0), "base=True, override=0"),
+ (0, None, OutputMultiplicityResolution(resolved_multiplicity=0, is_multiple_outputs_enabled=True, specific_output_count=0), "base=0, override=None"),
+ (True, 0, OutputMultiplicityResolution(resolved_multiplicity=0, is_multiple_outputs_enabled=True, specific_output_count=0), "base=True, override=0"),
# Large numbers
(
1000,
None,
- OutputMultiplicityResolution(resolved_multiplicity=1000, enable_multiple_outputs=True, specific_output_count=1000),
+ OutputMultiplicityResolution(resolved_multiplicity=1000, is_multiple_outputs_enabled=True, specific_output_count=1000),
"base=1000, override=None",
),
(
100,
999,
- OutputMultiplicityResolution(resolved_multiplicity=999, enable_multiple_outputs=True, specific_output_count=999),
+ OutputMultiplicityResolution(resolved_multiplicity=999, is_multiple_outputs_enabled=True, specific_output_count=999),
"base=100, override=999",
),
]
diff --git a/tests/unit/pipelex/core/pipes/test_pipe_run_params.py b/tests/unit/pipelex/core/pipes/test_pipe_run_params.py
index 3e96e7027..906366bbb 100644
--- a/tests/unit/pipelex/core/pipes/test_pipe_run_params.py
+++ b/tests/unit/pipelex/core/pipes/test_pipe_run_params.py
@@ -120,7 +120,7 @@ class TestOutputMultiplicityToApply:
"""Test output_multiplicity_to_apply with all parameter combinations."""
result = output_multiplicity_to_apply(base, override)
assert result.resolved_multiplicity == expected_result.resolved_multiplicity, f"Failed resolved_multiplicity for case: {description}"
- assert result.enable_multiple_outputs == expected_result.enable_multiple_outputs, f"Failed enable_multiple_outputs for case: {description}"
+ assert result.is_multiple_outputs_enabled == expected_result.is_multiple_outputs_enabled, f"Failed enable_multiple_outputs for case: {description}"
assert result.specific_output_count == expected_result.specific_output_count, f"Failed specific_output_count for case: {description}"
def test_override_none_uses_base(self):
@@ -128,25 +128,25 @@ class TestOutputMultiplicityToApply:
# Base None -> single output
result = output_multiplicity_to_apply(None, None)
assert result.resolved_multiplicity is None
- assert result.enable_multiple_outputs is False
+ assert result.is_multiple_outputs_enabled is False
assert result.specific_output_count is None
# Base True -> multiple output, LLM decides
result = output_multiplicity_to_apply(base_multiplicity=True, override_multiplicity=None)
assert result.resolved_multiplicity is True
- assert result.enable_multiple_outputs is True
+ assert result.is_multiple_outputs_enabled is True
assert result.specific_output_count is None
# Base int -> multiple output with specific count
result = output_multiplicity_to_apply(base_multiplicity=3, override_multiplicity=None)
assert result.resolved_multiplicity == 3
- assert result.enable_multiple_outputs is True
+ assert result.is_multiple_outputs_enabled is True
assert result.specific_output_count == 3
# Base False -> single output
result = output_multiplicity_to_apply(base_multiplicity=False, override_multiplicity=None)
assert result.resolved_multiplicity is False
- assert result.enable_multiple_outputs is False
+ assert result.is_multiple_outputs_enabled is False
assert result.specific_output_count is None
def test_override_false_forces_single_output(self):
@@ -157,7 +157,7 @@ class TestOutputMultiplicityToApply:
for base in test_bases:
result = output_multiplicity_to_apply(base_multiplicity=base, override_multiplicity=False)
assert result.resolved_multiplicity is False, f"Failed for base={base}: resolved_multiplicity should be False"
- assert result.enable_multiple_outputs is False, f"Failed for base={base}: enable_multiple_outputs should be False"
+ assert result.is_multiple_outputs_enabled is False, f"Failed for base={base}: enable_multiple_outputs should be False"
assert result.specific_output_count is None, f"Failed for base={base}: specific_output_count should be None"
def test_override_true_enables_multiple_outputs(self):
@@ -165,26 +165,26 @@ class TestOutputMultiplicityToApply:
# Base None -> preserve None but enable multiple
result = output_multiplicity_to_apply(base_multiplicity=None, override_multiplicity=True)
assert result.resolved_multiplicity is None
- assert result.enable_multiple_outputs is True
+ assert result.is_multiple_outputs_enabled is True
assert result.specific_output_count is None
# Base False -> enable multiple, LLM decides count
result = output_multiplicity_to_apply(base_multiplicity=False, override_multiplicity=True)
assert result.resolved_multiplicity is True
- assert result.enable_multiple_outputs is True
+ assert result.is_multiple_outputs_enabled is True
assert result.specific_output_count is None
# Base True -> keep True
result = output_multiplicity_to_apply(base_multiplicity=True, override_multiplicity=True)
assert result.resolved_multiplicity is True
- assert result.enable_multiple_outputs is True
+ assert result.is_multiple_outputs_enabled is True
assert result.specific_output_count is None
# Base int -> preserve count, enable multiple
for base_int in [1, 3, 5, 10]:
result = output_multiplicity_to_apply(base_multiplicity=base_int, override_multiplicity=True)
assert result.resolved_multiplicity == base_int
- assert result.enable_multiple_outputs is True
+ assert result.is_multiple_outputs_enabled is True
assert result.specific_output_count == base_int
def test_override_int_uses_override_count(self):
@@ -195,7 +195,7 @@ class TestOutputMultiplicityToApply:
for base in test_bases:
result = output_multiplicity_to_apply(base_multiplicity=base, override_multiplicity=override_int)
assert result.resolved_multiplicity == override_int, f"Failed for base={base}: resolved_multiplicity should be {override_int}"
- assert result.enable_multiple_outputs is True, f"Failed for base={base}: enable_multiple_outputs should be True"
+ assert result.is_multiple_outputs_enabled is True, f"Failed for base={base}: enable_multiple_outputs should be True"
assert result.specific_output_count == override_int, f"Failed for base={base}: specific_output_count should be {override_int}"
def test_return_basemodel_structure(self):
@@ -205,7 +205,7 @@ class TestOutputMultiplicityToApply:
# Test field types
assert result.resolved_multiplicity is None or isinstance(result.resolved_multiplicity, (bool, int))
- assert isinstance(result.enable_multiple_outputs, bool)
+ assert isinstance(result.is_multiple_outputs_enabled, bool)
assert result.specific_output_count is None or isinstance(result.specific_output_count, int)
def test_edge_cases(self):
@@ -213,29 +213,29 @@ class TestOutputMultiplicityToApply:
# Negative numbers
result = output_multiplicity_to_apply(base_multiplicity=-1, override_multiplicity=None)
assert result.resolved_multiplicity == -1
- assert result.enable_multiple_outputs is True
+ assert result.is_multiple_outputs_enabled is True
assert result.specific_output_count == -1
result = output_multiplicity_to_apply(base_multiplicity=3, override_multiplicity=-2)
assert result.resolved_multiplicity == -2
- assert result.enable_multiple_outputs is True
+ assert result.is_multiple_outputs_enabled is True
assert result.specific_output_count == -2
# Zero values
result = output_multiplicity_to_apply(base_multiplicity=0, override_multiplicity=None)
assert result.resolved_multiplicity == 0
- assert result.enable_multiple_outputs is True
+ assert result.is_multiple_outputs_enabled is True
assert result.specific_output_count == 0
result = output_multiplicity_to_apply(base_multiplicity=True, override_multiplicity=0)
assert result.resolved_multiplicity == 0
- assert result.enable_multiple_outputs is True
+ assert result.is_multiple_outputs_enabled is True
assert result.specific_output_count == 0
# Large numbers
result = output_multiplicity_to_apply(base_multiplicity=1000, override_multiplicity=None)
assert result.resolved_multiplicity == 1000
- assert result.enable_multiple_outputs is True
+ assert result.is_multiple_outputs_enabled is True
assert result.specific_output_count == 1000
def test_override_precedence_logic(self):
@@ -243,40 +243,40 @@ class TestOutputMultiplicityToApply:
# Override False beats any base
result = output_multiplicity_to_apply(base_multiplicity=True, override_multiplicity=False)
assert result.resolved_multiplicity is False
- assert result.enable_multiple_outputs is False
+ assert result.is_multiple_outputs_enabled is False
assert result.specific_output_count is None
result = output_multiplicity_to_apply(base_multiplicity=5, override_multiplicity=False)
assert result.resolved_multiplicity is False
- assert result.enable_multiple_outputs is False
+ assert result.is_multiple_outputs_enabled is False
assert result.specific_output_count is None
# Override int beats any base
result = output_multiplicity_to_apply(base_multiplicity=True, override_multiplicity=3)
assert result.resolved_multiplicity == 3
- assert result.enable_multiple_outputs is True
+ assert result.is_multiple_outputs_enabled is True
assert result.specific_output_count == 3
result = output_multiplicity_to_apply(base_multiplicity=7, override_multiplicity=3)
assert result.resolved_multiplicity == 3
- assert result.enable_multiple_outputs is True
+ assert result.is_multiple_outputs_enabled is True
assert result.specific_output_count == 3
# Override True with int base preserves int
result = output_multiplicity_to_apply(base_multiplicity=5, override_multiplicity=True)
assert result.resolved_multiplicity == 5
- assert result.enable_multiple_outputs is True
+ assert result.is_multiple_outputs_enabled is True
assert result.specific_output_count == 5
# Override True with bool base becomes True
result = output_multiplicity_to_apply(base_multiplicity=True, override_multiplicity=True)
assert result.resolved_multiplicity is True
- assert result.enable_multiple_outputs is True
+ assert result.is_multiple_outputs_enabled is True
assert result.specific_output_count is None
result = output_multiplicity_to_apply(base_multiplicity=False, override_multiplicity=True)
assert result.resolved_multiplicity is True
- assert result.enable_multiple_outputs is True
+ assert result.is_multiple_outputs_enabled is True
assert result.specific_output_count is None
def test_complex_scenarios(self):
@@ -284,23 +284,23 @@ class TestOutputMultiplicityToApply:
# Scenario: Pipe has base multiplicity=3, runtime wants to disable it
result = output_multiplicity_to_apply(base_multiplicity=3, override_multiplicity=False)
assert result.resolved_multiplicity is False
- assert result.enable_multiple_outputs is False
+ assert result.is_multiple_outputs_enabled is False
assert result.specific_output_count is None
# Scenario: Pipe has no base multiplicity, runtime wants 5 outputs
result = output_multiplicity_to_apply(base_multiplicity=None, override_multiplicity=5)
assert result.resolved_multiplicity == 5
- assert result.enable_multiple_outputs is True
+ assert result.is_multiple_outputs_enabled is True
assert result.specific_output_count == 5
# Scenario: Pipe has base True, runtime wants specific count
result = output_multiplicity_to_apply(base_multiplicity=True, override_multiplicity=2)
assert result.resolved_multiplicity == 2
- assert result.enable_multiple_outputs is True
+ assert result.is_multiple_outputs_enabled is True
assert result.specific_output_count == 2
# Scenario: Pipe has base count, runtime wants to enable but let LLM decide
result = output_multiplicity_to_apply(base_multiplicity=4, override_multiplicity=True)
assert result.resolved_multiplicity == 4 # Preserves base count
- assert result.enable_multiple_outputs is True
+ assert result.is_multiple_outputs_enabled is True
assert result.specific_output_count == 4
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/concept/test_concept_blueprint.py b/tests/unit/pipelex/libraries/pipelines/builder/concept/test_concept_blueprint.py
index b6c5a1bae..9e765c6a5 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/concept/test_concept_blueprint.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/concept/test_concept_blueprint.py
@@ -1,16 +1,43 @@
import pytest
+from pipelex import log
from pipelex.core.concepts.concept_blueprint import ConceptBlueprint
from pipelex.libraries.pipelines.builder.concept.concept_spec import ConceptSpec
-from .test_data import ConceptBlueprintTestCases
+from tests.unit.pipelex.libraries.pipelines.builder.concept.test_data import ConceptBlueprintTestCases, ConceptCodeValidationTestCases
class TestConceptBlueprintConversion:
@pytest.mark.parametrize(
- "test_name,concept_spec,expected_core",
+ "topic,concept_spec,expected_core",
ConceptBlueprintTestCases.TEST_CASES,
)
- def test_concept_to_core_blueprint(self, test_name: str, concept_spec: ConceptSpec, expected_core: ConceptBlueprint):
+ def test_concept_to_core_blueprint(self, topic: str, concept_spec: ConceptSpec, expected_core: ConceptBlueprint):
+ log.verbose(f"Testing {topic}")
result = concept_spec.to_blueprint()
assert result == expected_core
+
+
+class TestConceptCodeValidation:
+ """Tests for concept code validation and snake_case to PascalCase conversion."""
+
+ @pytest.mark.parametrize(
+ "topic,input_code,expected_code",
+ ConceptCodeValidationTestCases.TEST_CASES,
+ )
+ def test_concept_code_conversion(self, topic: str, input_code: str, expected_code: str):
+ """Test that concept codes are properly converted from snake_case to PascalCase."""
+ log.verbose(f"Testing {topic}: '{input_code}' -> '{expected_code}'")
+
+ # Create a ConceptSpec with the input code
+ concept_spec = ConceptSpec(
+ the_concept_code=input_code,
+ definition="Test concept for code validation",
+ refines=None,
+ structure=None,
+ )
+
+ # Verify the concept code was converted correctly
+ assert concept_spec.the_concept_code == expected_code, (
+ f"Expected concept code to be '{expected_code}', but got '{concept_spec.the_concept_code}'"
+ )
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/concept/test_data.py b/tests/unit/pipelex/libraries/pipelines/builder/concept/test_data.py
index 27152474f..923dfb74c 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/concept/test_data.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/concept/test_data.py
@@ -153,3 +153,82 @@ class ConceptBlueprintTestCases:
CONCEPT_WITH_INTEGER_FIELD,
CONCEPT_WITH_MULTIPLE_FIELDS,
]
+
+
+class ConceptCodeValidationTestCases:
+ """Test cases for concept code validation and snake_case to PascalCase conversion."""
+
+ # Test case: snake_case without domain -> PascalCase
+ SNAKE_CASE_NO_DOMAIN = (
+ "snake_case_no_domain",
+ "concept_name",
+ "ConceptName",
+ )
+
+ # Test case: PascalCase without domain -> unchanged
+ PASCAL_CASE_NO_DOMAIN = (
+ "pascal_case_no_domain",
+ "ConceptName",
+ "ConceptName",
+ )
+
+ # Test case: snake_case with domain -> domain.PascalCase
+ SNAKE_CASE_WITH_DOMAIN = (
+ "snake_case_with_domain",
+ "my_domain.concept_name",
+ "my_domain.ConceptName",
+ )
+
+ # Test case: PascalCase with domain -> unchanged
+ PASCAL_CASE_WITH_DOMAIN = (
+ "pascal_case_with_domain",
+ "my_domain.ConceptName",
+ "my_domain.ConceptName",
+ )
+
+ # Test case: mixed case with domain -> domain.PascalCase
+ MIXED_CASE_WITH_DOMAIN = (
+ "mixed_case_with_domain",
+ "my_domain.some_complex_concept_name",
+ "my_domain.SomeComplexConceptName",
+ )
+
+ # Test case: single word snake_case -> PascalCase
+ SINGLE_WORD_SNAKE = (
+ "single_word_snake",
+ "concept",
+ "Concept",
+ )
+
+ # Test case: multiple underscores -> PascalCase
+ MULTIPLE_UNDERSCORES = (
+ "multiple_underscores",
+ "my_super_long_concept_name",
+ "MySuperLongConceptName",
+ )
+
+ # Test case: with numbers in snake_case
+ WITH_NUMBERS_SNAKE = (
+ "with_numbers_snake",
+ "concept_v2_name",
+ "ConceptV2Name",
+ )
+
+ # Test case: with numbers in domain.snake_case
+ WITH_NUMBERS_DOMAIN_SNAKE = (
+ "with_numbers_domain_snake",
+ "domain_v1.concept_name_v2",
+ "domain_v1.ConceptNameV2",
+ )
+
+ TEST_CASES: ClassVar[list[tuple[str, str, str]]] = [
+ SNAKE_CASE_NO_DOMAIN,
+ PASCAL_CASE_NO_DOMAIN,
+ SNAKE_CASE_WITH_DOMAIN,
+ PASCAL_CASE_WITH_DOMAIN,
+ MIXED_CASE_WITH_DOMAIN,
+ SINGLE_WORD_SNAKE,
+ MULTIPLE_UNDERSCORES,
+ WITH_NUMBERS_SNAKE,
+ WITH_NUMBERS_DOMAIN_SNAKE,
+ ]
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_batch/test_data.py b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_batch/test_data.py
index eee197946..dc2bf8769 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_batch/test_data.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_batch/test_data.py
@@ -1,7 +1,6 @@
from typing import ClassVar
from pipelex.core.pipes.pipe_input_blueprint import InputRequirementBlueprint
-from pipelex.libraries.pipelines.builder.pipe.inputs_spec import InputRequirementSpec
from pipelex.libraries.pipelines.builder.pipe.pipe_batch_spec import PipeBatchSpec
from pipelex.pipe_controllers.batch.pipe_batch_blueprint import PipeBatchBlueprint
@@ -12,7 +11,7 @@ class PipeBatchTestCases:
PipeBatchSpec(
the_pipe_code="batch_processor",
definition="Process items in batch",
- inputs={"items": InputRequirementSpec(concept="ItemList")},
+ inputs={"items": "ItemList"},
output="ProcessedItems",
branch_pipe_code="process_item",
),
@@ -33,7 +32,7 @@ class PipeBatchTestCases:
PipeBatchSpec(
the_pipe_code="named_batch",
definition="Batch with custom names",
- inputs={"data": InputRequirementSpec(concept="DataList")},
+ inputs={"data": "DataList"},
output="Results",
branch_pipe_code="transform_data",
input_list_name="data_list",
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_batch/test_pipe_batch.py b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_batch/test_pipe_batch.py
index eec8f555d..70061c8f4 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_batch/test_pipe_batch.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_batch/test_pipe_batch.py
@@ -3,7 +3,7 @@ import pytest
from pipelex.libraries.pipelines.builder.pipe.pipe_batch_spec import PipeBatchSpec
from pipelex.pipe_controllers.batch.pipe_batch_blueprint import PipeBatchBlueprint
-from .test_data import PipeBatchTestCases
+from tests.unit.pipelex.libraries.pipelines.builder.pipe.pipe_controllers.pipe_batch.test_data import PipeBatchTestCases
class TestPipeBatchBlueprintConversion:
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_condition/test_data.py b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_condition/test_data.py
index fa7f84917..f23694221 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_condition/test_data.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_condition/test_data.py
@@ -1,63 +1,27 @@
from typing import ClassVar
from pipelex.core.pipes.pipe_input_blueprint import InputRequirementBlueprint
-from pipelex.libraries.pipelines.builder.pipe.inputs_spec import InputRequirementSpec
-from pipelex.libraries.pipelines.builder.pipe.pipe_condition_spec import PipeConditionPipeMapSpec, PipeConditionSpec
+
+from pipelex.libraries.pipelines.builder.pipe.pipe_condition_spec import PipeConditionSpec
from pipelex.pipe_controllers.condition.pipe_condition_blueprint import PipeConditionBlueprint, PipeConditionPipeMapBlueprint
class PipeConditionTestCases:
- SIMPLE_CONDITION = (
- "simple_condition",
- PipeConditionSpec(
- the_pipe_code="conditional_processor",
- definition="Choose pipe based on condition",
- inputs={"data": InputRequirementSpec(concept="Data")},
- output="Result",
- expression="data.status",
- pipe_map=PipeConditionPipeMapSpec(
- root={
- "active": "process_active",
- "inactive": "process_inactive",
- },
- ),
- ),
- PipeConditionBlueprint(
- definition="Choose pipe based on condition",
- inputs={"data": InputRequirementBlueprint(concept="Data")},
- output="Result",
- type="PipeCondition",
- category="PipeController",
- expression="data.status",
- expression_template=None,
- pipe_map=PipeConditionPipeMapBlueprint(
- root={
- "active": "process_active",
- "inactive": "process_inactive",
- },
- ),
- default_pipe_code=None,
- add_alias_from_expression_to=None,
- ),
- )
CONDITION_WITH_TEMPLATE = (
"condition_with_template",
PipeConditionSpec(
the_pipe_code="template_condition",
definition="Conditional with template",
- inputs={"item": InputRequirementSpec(concept="Item")},
+ inputs={"item": "Item"},
output="ProcessedItem",
- expression_template="{{ item.category }}",
- pipe_map=PipeConditionPipeMapSpec(
- root={
+ jinja2_expression_template="{{ item.category }}",
+ pipe_map={
"A": "process_a",
"B": "process_b",
"C": "process_c",
},
- ),
default_pipe_code="process_default",
- add_alias_from_expression_to="category_result",
),
PipeConditionBlueprint(
definition="Conditional with template",
@@ -75,11 +39,10 @@ class PipeConditionTestCases:
},
),
default_pipe_code="process_default",
- add_alias_from_expression_to="category_result",
+ add_alias_from_expression_to=None,
),
)
TEST_CASES: ClassVar[list[tuple[str, PipeConditionSpec, PipeConditionBlueprint]]] = [
- SIMPLE_CONDITION,
CONDITION_WITH_TEMPLATE,
]
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_condition/test_pipe_condition.py b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_condition/test_pipe_condition.py
index 6820e806b..90697b6e8 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_condition/test_pipe_condition.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_condition/test_pipe_condition.py
@@ -3,7 +3,7 @@ import pytest
from pipelex.libraries.pipelines.builder.pipe.pipe_condition_spec import PipeConditionSpec
from pipelex.pipe_controllers.condition.pipe_condition_blueprint import PipeConditionBlueprint
-from .test_data import PipeConditionTestCases
+from tests.unit.pipelex.libraries.pipelines.builder.pipe.pipe_controllers.pipe_condition.test_data import PipeConditionTestCases
class TestPipeConditionBlueprintConversion:
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_parallel/test_data.py b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_parallel/test_data.py
index 63fbca416..6fc5cad91 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_parallel/test_data.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_parallel/test_data.py
@@ -1,7 +1,7 @@
from typing import ClassVar
from pipelex.core.pipes.pipe_input_blueprint import InputRequirementBlueprint
-from pipelex.libraries.pipelines.builder.pipe.inputs_spec import InputRequirementSpec
+
from pipelex.libraries.pipelines.builder.pipe.pipe_parallel_spec import PipeParallelSpec
from pipelex.libraries.pipelines.builder.pipe.sub_pipe_spec import SubPipeSpec
from pipelex.pipe_controllers.parallel.pipe_parallel_blueprint import PipeParallelBlueprint
@@ -14,7 +14,7 @@ class PipeParallelTestCases:
PipeParallelSpec(
the_pipe_code="parallel_processor",
definition="Run pipes in parallel",
- inputs={"data": InputRequirementSpec(concept="Data")},
+ inputs={"data": "Data"},
output="Results",
parallels=[
SubPipeSpec(the_pipe_code="analyze_data", result="analysis"),
@@ -45,7 +45,7 @@ class PipeParallelTestCases:
PipeParallelSpec(
the_pipe_code="combined_parallel",
definition="Parallel with combined output",
- inputs={"input": InputRequirementSpec(concept="Input")},
+ inputs={"input": "Input"},
output="CombinedResult",
parallels=[
SubPipeSpec(the_pipe_code="pipe1", result="result1"),
@@ -75,7 +75,7 @@ class PipeParallelTestCases:
PipeParallelSpec(
the_pipe_code="combined_parallel",
definition="Parallel with combined output",
- inputs={"input": InputRequirementSpec(concept="Input")},
+ inputs={"input": "Input"},
output="CombinedResult",
parallels=[
SubPipeSpec(the_pipe_code="pipe1", result="result1"),
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_parallel/test_pipe_parallel.py b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_parallel/test_pipe_parallel.py
index e35dd1669..6cfa30efd 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_parallel/test_pipe_parallel.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_parallel/test_pipe_parallel.py
@@ -3,7 +3,7 @@ import pytest
from pipelex.libraries.pipelines.builder.pipe.pipe_parallel_spec import PipeParallelSpec
from pipelex.pipe_controllers.parallel.pipe_parallel_blueprint import PipeParallelBlueprint
-from .test_data import PipeParallelTestCases
+from tests.unit.pipelex.libraries.pipelines.builder.pipe.pipe_controllers.pipe_parallel.test_data import PipeParallelTestCases
from pipelex import log
class TestPipeParallelBlueprintConversion:
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_sequence/test_data.py b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_sequence/test_data.py
index 75ee231b8..7d3429355 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_sequence/test_data.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_sequence/test_data.py
@@ -1,7 +1,7 @@
from typing import ClassVar
from pipelex.core.pipes.pipe_input_blueprint import InputRequirementBlueprint
-from pipelex.libraries.pipelines.builder.pipe.inputs_spec import InputRequirementSpec
+
from pipelex.libraries.pipelines.builder.pipe.pipe_sequence_spec import PipeSequenceSpec
from pipelex.libraries.pipelines.builder.pipe.sub_pipe_spec import SubPipeSpec
from pipelex.pipe_controllers.sequence.pipe_sequence_blueprint import PipeSequenceBlueprint
@@ -14,7 +14,7 @@ class PipeSequenceTestCases:
PipeSequenceSpec(
the_pipe_code="sequence_processor",
definition="A sequence of operations",
- inputs={"input_data": InputRequirementSpec(concept="Text")},
+ inputs={"input_data": "Text"},
output="ProcessedData",
steps=[
SubPipeSpec(the_pipe_code="step1", result="result1"),
@@ -41,7 +41,7 @@ class PipeSequenceTestCases:
PipeSequenceSpec(
the_pipe_code="batch_sequence",
definition="Sequence with batch",
- inputs={"items": InputRequirementSpec(concept="ItemList")},
+ inputs={"items": "ItemList"},
output="ProcessedItems",
steps=[
SubPipeSpec(the_pipe_code="prepare", result="prepared_items"),
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_sequence/test_pipe_sequence.py b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_sequence/test_pipe_sequence.py
index dbd99537c..f7762dec1 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_sequence/test_pipe_sequence.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_controllers/pipe_sequence/test_pipe_sequence.py
@@ -3,7 +3,7 @@ import pytest
from pipelex.libraries.pipelines.builder.pipe.pipe_sequence_spec import PipeSequenceSpec
from pipelex.pipe_controllers.sequence.pipe_sequence_blueprint import PipeSequenceBlueprint
-from .test_data import PipeSequenceTestCases
+from tests.unit.pipelex.libraries.pipelines.builder.pipe.pipe_controllers.pipe_sequence.test_data import PipeSequenceTestCases
class TestPipeSequenceBlueprintConversion:
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_func/test_data.py b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_func/test_data.py
index 4bfdf9bc6..32a365675 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_func/test_data.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_func/test_data.py
@@ -1,7 +1,7 @@
from typing import ClassVar
from pipelex.core.pipes.pipe_input_blueprint import InputRequirementBlueprint
-from pipelex.libraries.pipelines.builder.pipe.inputs_spec import InputRequirementSpec
+
from pipelex.libraries.pipelines.builder.pipe.pipe_func_spec import PipeFuncSpec
from pipelex.pipe_operators.func.pipe_func_blueprint import PipeFuncBlueprint
@@ -12,7 +12,7 @@ class PipeFuncTestCases:
PipeFuncSpec(
the_pipe_code="func_processor",
definition="Execute a function",
- inputs={"data": InputRequirementSpec(concept="Data")},
+ inputs={"data": "Data"},
output="ProcessedData",
function_name="process_data",
),
@@ -31,7 +31,7 @@ class PipeFuncTestCases:
PipeFuncSpec(
the_pipe_code="generator_func",
definition="Generate data",
- inputs=None,
+ inputs={},
output="GeneratedData",
function_name="generate_data",
),
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_func/test_pipe_func.py b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_func/test_pipe_func.py
index b735e19c8..84fc7a872 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_func/test_pipe_func.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_func/test_pipe_func.py
@@ -3,7 +3,7 @@ import pytest
from pipelex.libraries.pipelines.builder.pipe.pipe_func_spec import PipeFuncSpec
from pipelex.pipe_operators.func.pipe_func_blueprint import PipeFuncBlueprint
-from .test_data import PipeFuncTestCases
+from tests.unit.pipelex.libraries.pipelines.builder.pipe.pipe_operators.pipe_func.test_data import PipeFuncTestCases
class TestPipeFuncBlueprintConversion:
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_img/test_data.py b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_img/test_data.py
index e239f230b..8405376dd 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_img/test_data.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_img/test_data.py
@@ -2,8 +2,8 @@ from typing import ClassVar
from pipelex.cogt.img_gen.img_gen_job_components import AspectRatio
from pipelex.core.pipes.pipe_input_blueprint import InputRequirementBlueprint
-from pipelex.libraries.pipelines.builder.pipe.inputs_spec import InputRequirementSpec
-from pipelex.libraries.pipelines.builder.pipe.pipe_img_spec import PipeImgGenSpec
+
+from pipelex.libraries.pipelines.builder.pipe.pipe_img_spec import PipeImgGenSpec, RecommendedImgGen
from pipelex.pipe_operators.img_gen.pipe_img_gen_blueprint import PipeImgGenBlueprint
@@ -13,9 +13,8 @@ class PipeImgGenTestCases:
PipeImgGenSpec(
the_pipe_code="img_generator",
definition="Generate an image",
- inputs=None,
+ inputs={},
output="GeneratedImage",
- img_gen_prompt="A beautiful sunset over mountains",
),
PipeImgGenBlueprint(
definition="Generate an image",
@@ -23,7 +22,8 @@ class PipeImgGenTestCases:
output="GeneratedImage",
type="PipeImgGen",
category="PipeOperator",
- img_gen_prompt="A beautiful sunset over mountains",
+ img_gen_prompt=None,
+ img_gen_prompt_var_name=None,
img_gen=None,
aspect_ratio=None,
background=None,
@@ -31,7 +31,6 @@ class PipeImgGenTestCases:
nb_output=None,
is_raw=None,
seed=None,
- img_gen_prompt_var_name=None,
),
)
@@ -40,11 +39,9 @@ class PipeImgGenTestCases:
PipeImgGenSpec(
the_pipe_code="advanced_img_gen",
definition="Generate image with options",
- inputs={"description": InputRequirementSpec(concept="Text")},
+ inputs={"description": "Text"},
output="Image",
- img_gen="gpt-image-1",
- aspect_ratio=AspectRatio.SQUARE,
- seed=42,
+ img_gen=RecommendedImgGen.BASE_IMG_GEN,
nb_output=3,
),
PipeImgGenBlueprint(
@@ -54,12 +51,12 @@ class PipeImgGenTestCases:
type="PipeImgGen",
category="PipeOperator",
img_gen_prompt=None,
- img_gen="gpt-image-1",
- aspect_ratio=AspectRatio.SQUARE,
+ img_gen=RecommendedImgGen.BASE_IMG_GEN,
+ aspect_ratio=None,
background=None,
output_format=None,
is_raw=None,
- seed=42,
+ seed=None,
nb_output=3,
img_gen_prompt_var_name=None,
),
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_img/test_pipe_img.py b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_img/test_pipe_img.py
index 09f8c6aa9..4ee143bec 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_img/test_pipe_img.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_img/test_pipe_img.py
@@ -3,7 +3,7 @@ import pytest
from pipelex.libraries.pipelines.builder.pipe.pipe_img_spec import PipeImgGenSpec
from pipelex.pipe_operators.img_gen.pipe_img_gen_blueprint import PipeImgGenBlueprint
-from .test_data import PipeImgGenTestCases
+from tests.unit.pipelex.libraries.pipelines.builder.pipe.pipe_operators.pipe_img.test_data import PipeImgGenTestCases
class TestPipeImgGenBlueprintConversion:
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_jinja2/test_data.py b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_jinja2/test_data.py
index 28616ce78..5dc118973 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_jinja2/test_data.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_jinja2/test_data.py
@@ -1,8 +1,8 @@
from typing import ClassVar
from pipelex.core.pipes.pipe_input_blueprint import InputRequirementBlueprint
-from pipelex.libraries.pipelines.builder.pipe.inputs_spec import InputRequirementSpec
-from pipelex.libraries.pipelines.builder.pipe.pipe_compose_spec import PipeComposeSpec, PromptingStyleSpec
+
+from pipelex.libraries.pipelines.builder.pipe.pipe_compose_spec import PipeComposeSpec
from pipelex.pipe_operators.compose.pipe_compose_blueprint import PipeComposeBlueprint
from pipelex.tools.templating.jinja2_template_category import Jinja2TemplateCategory
from pipelex.tools.templating.templating_models import PromptingStyle, TagStyle, TextFormat
@@ -14,9 +14,10 @@ class PipeComposeTestCases:
PipeComposeSpec(
the_pipe_code="template_renderer",
definition="Render a template",
- inputs={"data": InputRequirementSpec(concept="Data")},
+ inputs={"data": "Data"},
output="RenderedText",
jinja2="Hello {{ data.name }}!",
+ target_format="markdown",
),
PipeComposeBlueprint(
definition="Render a template",
@@ -26,45 +27,15 @@ class PipeComposeTestCases:
category="PipeOperator",
jinja2_name=None,
jinja2="Hello {{ data.name }}!",
- prompting_style=None,
- template_category=Jinja2TemplateCategory.LLM_PROMPT,
- extra_context=None,
- ),
- )
-
- JINJA2_WITH_STYLE = (
- "jinja2_with_style",
- PipeComposeSpec(
- the_pipe_code="styled_template",
- definition="Template with prompting style",
- inputs={"input": InputRequirementSpec(concept="Input")},
- output="Output",
- jinja2_name="custom_template",
- prompting_style=PromptingStyleSpec(
- tag_style=TagStyle.XML,
- text_format=TextFormat.MARKDOWN,
- ),
- template_category=Jinja2TemplateCategory.MARKDOWN,
- extra_context={"version": "1.0"},
- ),
- PipeComposeBlueprint(
- definition="Template with prompting style",
- inputs={"input": InputRequirementBlueprint(concept="Input")},
- output="Output",
- type="PipeCompose",
- category="PipeOperator",
- jinja2_name="custom_template",
- jinja2=None,
prompting_style=PromptingStyle(
- tag_style=TagStyle.XML,
+ tag_style=TagStyle.TICKS,
text_format=TextFormat.MARKDOWN,
),
template_category=Jinja2TemplateCategory.MARKDOWN,
- extra_context={"version": "1.0"},
+ extra_context=None,
),
)
TEST_CASES: ClassVar[list[tuple[str, PipeComposeSpec, PipeComposeBlueprint]]] = [
SIMPLE_JINJA2,
- JINJA2_WITH_STYLE,
]
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_jinja2/test_pipe_jinja2.py b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_jinja2/test_pipe_jinja2.py
index cf72ba612..44e00bea4 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_jinja2/test_pipe_jinja2.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_jinja2/test_pipe_jinja2.py
@@ -3,7 +3,7 @@ import pytest
from pipelex.libraries.pipelines.builder.pipe.pipe_compose_spec import PipeComposeSpec
from pipelex.pipe_operators.compose.pipe_compose_blueprint import PipeComposeBlueprint
-from .test_data import PipeComposeTestCases
+from tests.unit.pipelex.libraries.pipelines.builder.pipe.pipe_operators.pipe_jinja2.test_data import PipeComposeTestCases
class TestPipeComposeBlueprintConversion:
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_llm/test_data.py b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_llm/test_data.py
index e3a6d25a7..f2dd30cbf 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_llm/test_data.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_llm/test_data.py
@@ -2,8 +2,8 @@ from typing import ClassVar
from pipelex.cogt.llm.llm_setting import LLMSetting
from pipelex.core.pipes.pipe_input_blueprint import InputRequirementBlueprint
-from pipelex.libraries.pipelines.builder.pipe.inputs_spec import InputRequirementSpec
-from pipelex.libraries.pipelines.builder.pipe.pipe_llm_spec import LLMSettingSpec, PipeLLMSpec
+
+from pipelex.libraries.pipelines.builder.pipe.pipe_llm_spec import PipeLLMSpec
from pipelex.pipe_operators.llm.pipe_llm_blueprint import PipeLLMBlueprint, StructuringMethod
@@ -13,16 +13,19 @@ class PipeLLMTestCases:
PipeLLMSpec(
the_pipe_code="test_pipe",
definition="Generate text",
- inputs={"topic": InputRequirementSpec(concept="Text")},
+ inputs={"topic": "Text"},
output="Text",
+ llm="llm_for_creative_writing",
prompt_template="Write about $topic",
),
PipeLLMBlueprint(
+ source=None,
type="PipeLLM",
definition="Generate text",
inputs={"topic": InputRequirementBlueprint(concept="Text")},
output="Text",
prompt_template="Write about $topic",
+ llm="claude-4.1-opus",
),
)
@@ -31,15 +34,18 @@ class PipeLLMTestCases:
PipeLLMSpec(
the_pipe_code="generate_pipe",
definition="Generate without inputs",
- inputs=None,
+ inputs={},
output="Text",
+ llm="llm_for_creative_writing",
prompt_template="Generate something interesting",
),
PipeLLMBlueprint(
+ source=None,
type="PipeLLM",
definition="Generate without inputs",
output="Text",
prompt_template="Generate something interesting",
+ llm="claude-4.1-opus",
),
)
@@ -48,15 +54,16 @@ class PipeLLMTestCases:
PipeLLMSpec(
the_pipe_code="generate",
definition="Generate with preset",
- inputs=None,
+ inputs={},
output="Text",
prompt_template="Generate text",
llm="llm_to_reason",
),
PipeLLMBlueprint(
+ source=None,
type="PipeLLM",
definition="Generate with preset",
- llm="llm_to_reason",
+ llm="claude-4-sonnet",
output="Text",
prompt_template="Generate text",
),
@@ -67,20 +74,18 @@ class PipeLLMTestCases:
PipeLLMSpec(
the_pipe_code="generate",
definition="Generate with settings",
- inputs=None,
+ inputs={},
output="Text",
prompt_template="Generate text",
- llm=LLMSettingSpec(
- llm_handle="gpt-4o-mini",
- temperature=0.7,
- max_tokens=None, # "auto" is handled at conversion to core
- ),
+ llm="llm_cheap_for_easy_questions",
+ temperature=0.7,
),
PipeLLMBlueprint(
+ source=None,
type="PipeLLM",
definition="Generate with settings",
llm=LLMSetting(
- llm_handle="gpt-4o-mini",
+ llm_handle="gpt-5-mini",
temperature=0.7,
max_tokens=None, # "auto" is handled at conversion to core
),
@@ -94,18 +99,21 @@ class PipeLLMTestCases:
PipeLLMSpec(
the_pipe_code="analyze",
definition="Generate with system prompt",
- inputs={"data": InputRequirementSpec(concept="Data")},
+ inputs={"data": "Data"},
output="Analysis",
system_prompt="You are a data analyst",
prompt_template="Analyze: @data",
+ llm="llm_to_analyze_data",
),
PipeLLMBlueprint(
+ source=None,
type="PipeLLM",
definition="Generate with system prompt",
inputs={"data": InputRequirementBlueprint(concept="Data")},
system_prompt="You are a data analyst",
prompt_template="Analyze: @data",
output="Analysis",
+ llm="claude-4-sonnet",
),
)
@@ -114,18 +122,21 @@ class PipeLLMTestCases:
PipeLLMSpec(
the_pipe_code="generate_items",
definition="Generate multiple items",
- inputs=None,
+ inputs={},
output="Item",
prompt_template="Generate items",
multiple_output=True,
+ llm="llm_cheap_for_easy_questions",
),
PipeLLMBlueprint(
+ source=None,
type="PipeLLM",
definition="Generate multiple items",
multiple_output=True,
nb_output=None,
output="Item",
prompt_template="Generate items",
+ llm="gpt-5-mini",
),
)
@@ -134,53 +145,21 @@ class PipeLLMTestCases:
PipeLLMSpec(
the_pipe_code="generate_items",
definition="Generate exactly 5 items",
- inputs=None,
+ inputs={},
output="Item",
prompt_template="Generate items",
nb_output=5,
+ llm="llm_cheap_for_easy_questions",
),
PipeLLMBlueprint(
+ source=None,
type="PipeLLM",
definition="Generate exactly 5 items",
nb_output=5,
multiple_output=None,
output="Item",
prompt_template="Generate items",
- ),
- )
-
- LLM_WITH_STRUCTURING = (
- "llm_with_structuring",
- PipeLLMSpec(
- the_pipe_code="test_pipe",
- definition="Extract structured data",
- inputs=None,
- output="PersonInfo",
- prompt_template="Extract person info",
- llm="llm_to_extract",
- llm_to_structure=LLMSettingSpec(
- llm_handle="claude-3-sonnet",
- temperature=0.1,
- max_tokens=None, # "auto" is handled at conversion to core
- ),
- structuring_method=StructuringMethod.PRELIMINARY_TEXT,
- prompt_template_to_structure="Structure the output",
- system_prompt_to_structure="You are a data structurer",
- ),
- PipeLLMBlueprint(
- type="PipeLLM",
- definition="Extract structured data",
- structuring_method=StructuringMethod.PRELIMINARY_TEXT,
- prompt_template_to_structure="Structure the output",
- system_prompt_to_structure="You are a data structurer",
- llm="llm_to_extract",
- llm_to_structure=LLMSetting(
- llm_handle="claude-3-sonnet",
- temperature=0.1,
- max_tokens=None, # "auto" is handled at conversion to core
- ),
- output="PersonInfo",
- prompt_template="Extract person info",
+ llm="gpt-5-mini",
),
)
@@ -192,5 +171,4 @@ class PipeLLMTestCases:
LLM_WITH_SYSTEM_PROMPT,
LLM_WITH_MULTIPLE_OUTPUT,
LLM_WITH_FIXED_OUTPUT,
- LLM_WITH_STRUCTURING,
]
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_llm/test_pipe_llm.py b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_llm/test_pipe_llm.py
index 88288672e..252c57b44 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_llm/test_pipe_llm.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_llm/test_pipe_llm.py
@@ -3,7 +3,7 @@ import pytest
from pipelex.libraries.pipelines.builder.pipe.pipe_llm_spec import PipeLLMSpec
from pipelex.pipe_operators.llm.pipe_llm_blueprint import PipeLLMBlueprint
-from .test_data import PipeLLMTestCases
+from tests.unit.pipelex.libraries.pipelines.builder.pipe.pipe_operators.pipe_llm.test_data import PipeLLMTestCases
class TestPipeLLMBlueprintConversion:
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_ocr/test_data.py b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_ocr/test_data.py
index 653c80549..43e5be73c 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_ocr/test_data.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_ocr/test_data.py
@@ -1,7 +1,7 @@
from typing import ClassVar
from pipelex.core.pipes.pipe_input_blueprint import InputRequirementBlueprint
-from pipelex.libraries.pipelines.builder.pipe.inputs_spec import InputRequirementSpec
+
from pipelex.libraries.pipelines.builder.pipe.pipe_ocr_spec import PipeOcrSpec
from pipelex.pipe_operators.ocr.pipe_ocr_blueprint import PipeOcrBlueprint
@@ -12,11 +12,12 @@ class PipeOcrTestCases:
PipeOcrSpec(
the_pipe_code="ocr_extractor",
definition="Extract text from image",
- inputs={"image": InputRequirementSpec(concept="Image")},
+ inputs={"image": "Image"},
output="ExtractedText",
- ocr="base_ocr_mistral",
+ ocr="extract_text_from_visuals",
),
PipeOcrBlueprint(
+ source=None,
definition="Extract text from image",
inputs={"image": InputRequirementBlueprint(concept="Image")},
output="ExtractedText",
@@ -31,21 +32,25 @@ class PipeOcrTestCases:
PipeOcrSpec(
the_pipe_code="advanced_ocr",
definition="OCR with page options",
- inputs={"document": InputRequirementSpec(concept="PDF")},
+ inputs={"document": "PDF"},
output="PageContent",
- ocr="base_ocr_mistral",
+ ocr="extract_text_from_pdf",
page_images=True,
page_image_captions=True,
page_views=True,
- page_views_dpi=300,
),
PipeOcrBlueprint(
+ source=None,
definition="OCR with page options",
inputs={"document": InputRequirementBlueprint(concept="PDF")},
output="PageContent",
type="PipeOcr",
category="PipeOperator",
ocr="base_ocr_mistral",
+ page_images=True,
+ page_image_captions=True,
+ page_views=True,
+ page_views_dpi=None,
),
)
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_ocr/test_pipe_ocr.py b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_ocr/test_pipe_ocr.py
index d3d63b25b..48ee34aaf 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_ocr/test_pipe_ocr.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_ocr/test_pipe_ocr.py
@@ -4,7 +4,7 @@ from pipelex.libraries.pipelines.builder.pipe.pipe_ocr_spec import PipeOcrSpec
from pipelex.pipe_operators.ocr.pipe_ocr_blueprint import PipeOcrBlueprint
from pipelex import log
-from .test_data import PipeOcrTestCases
+from tests.unit.pipelex.libraries.pipelines.builder.pipe.pipe_operators.pipe_ocr.test_data import PipeOcrTestCases
class TestPipeOcrBlueprintConversion:
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/pipe/test_data_inputs.py b/tests/unit/pipelex/libraries/pipelines/builder/pipe/test_data_inputs.py
index 77f1856e8..037c95835 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/pipe/test_data_inputs.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/pipe/test_data_inputs.py
@@ -1,39 +1,39 @@
from typing import ClassVar
from pipelex.core.pipes.pipe_input_blueprint import InputRequirementBlueprint
-from pipelex.libraries.pipelines.builder.pipe.inputs_spec import InputRequirementSpec
+
class InputRequirementTestCases:
SIMPLE_TEXT_INPUT = (
"simple_text_input",
- InputRequirementSpec(concept="Text"),
+ "Text",
"test_domain",
InputRequirementBlueprint(concept="Text"),
)
IMAGE_INPUT = (
"image_input",
- InputRequirementSpec(concept="Image"),
+ "Image",
"test_domain",
InputRequirementBlueprint(concept="Image"),
)
CUSTOM_CONCEPT_INPUT = (
"custom_concept_input",
- InputRequirementSpec(concept="CustomConcept"),
+ "CustomConcept",
"test_domain",
InputRequirementBlueprint(concept="CustomConcept"),
)
DOMAIN_CONCEPT_INPUT = (
"domain_concept_input",
- InputRequirementSpec(concept="domain.ConceptName"),
+ "domain.ConceptName",
"test_domain",
InputRequirementBlueprint(concept="domain.ConceptName"),
)
- TEST_CASES: ClassVar[list[tuple[str, InputRequirementSpec, str, InputRequirementBlueprint]]] = [
+ TEST_CASES: ClassVar[list[tuple[str, str, str, InputRequirementBlueprint]]] = [
SIMPLE_TEXT_INPUT,
IMAGE_INPUT,
CUSTOM_CONCEPT_INPUT,
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/pipe/test_data_pipe.py b/tests/unit/pipelex/libraries/pipelines/builder/pipe/test_data_pipe.py
index f52961f78..38f1f43ec 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/pipe/test_data_pipe.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/pipe/test_data_pipe.py
@@ -2,7 +2,7 @@ from typing import ClassVar
from pipelex.core.pipes.pipe_blueprint import PipeBlueprint
from pipelex.core.pipes.pipe_input_blueprint import InputRequirementBlueprint
-from pipelex.libraries.pipelines.builder.pipe.inputs_spec import InputRequirementSpec
+
from pipelex.libraries.pipelines.builder.pipe.pipe_signature import PipeSpec
@@ -32,8 +32,8 @@ class PipeBlueprintTestCases:
category="PipeOperator",
definition="Pipe with input requirements",
inputs={
- "data": InputRequirementSpec(concept="Data"),
- "config": InputRequirementSpec(concept="Config"),
+ "data": "Data",
+ "config": "Config",
},
output="Result",
),
@@ -55,7 +55,7 @@ class PipeBlueprintTestCases:
type="PipeFunc",
category="PipeOperator",
definition="Pipe without inputs",
- inputs=None,
+ inputs={},
output="GeneratedData",
),
PipeBlueprint(
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/pipe/test_inputs_blueprint.py b/tests/unit/pipelex/libraries/pipelines/builder/pipe/test_inputs_blueprint.py
index 53cfdfb3e..e4026fc23 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/pipe/test_inputs_blueprint.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/pipe/test_inputs_blueprint.py
@@ -1,7 +1,7 @@
import pytest
from pipelex.core.pipes.pipe_input_blueprint import InputRequirementBlueprint
-from pipelex.libraries.pipelines.builder.pipe.inputs_spec import InputRequirementSpec
+
from .test_data_inputs import InputRequirementTestCases
@@ -12,7 +12,7 @@ class TestInputRequirementBlueprintConversion:
InputRequirementTestCases.TEST_CASES,
)
def test_input_requirement_spec_to_blueprint(
- self, test_name: str, input_spec: InputRequirementSpec, domain: str, expected_blueprint: InputRequirementBlueprint,
+ self, test_name: str, input_spec: str, domain: str, expected_blueprint: InputRequirementBlueprint
):
- result = input_spec.to_blueprint()
+ result = InputRequirementBlueprint(concept=input_spec)
assert result == expected_blueprint
diff --git a/tests/unit/pipelex/tools/misc/test_toml_utils.py b/tests/unit/pipelex/tools/misc/test_toml_utils.py
index 9980dea8e..66b9670cc 100644
--- a/tests/unit/pipelex/tools/misc/test_toml_utils.py
+++ b/tests/unit/pipelex/tools/misc/test_toml_utils.py
@@ -3,10 +3,8 @@ from pathlib import Path
import pytest
from pipelex.tools.misc.toml_utils import (
- TOMLValidationError,
load_toml_from_path_if_exists,
load_toml_from_path,
- validate_toml_file,
)
@@ -46,14 +44,6 @@ definition = "Test"
toml_file = tmp_path / "trailing_space.toml"
toml_file.write_text(toml_content)
- with pytest.raises(TOMLValidationError) as exc_info:
- validate_toml_file(str(toml_file))
-
- error_msg = str(exc_info.value)
- assert "Trailing whitespace detected" in error_msg
- assert "Line 1" in error_msg
- assert "Line 2" in error_msg
-
def test_validate_toml_file_trailing_space_after_triple_quotes(self, tmp_path: Path) -> None:
"""Test detection of trailing whitespace after triple quotes."""
toml_content = '''domain = "test"
@@ -68,13 +58,6 @@ Output this only: "test"
toml_file = tmp_path / "trailing_quotes.toml"
toml_file.write_text(toml_content)
- with pytest.raises(TOMLValidationError) as exc_info:
- validate_toml_file(str(toml_file))
-
- error_msg = str(exc_info.value)
- assert "Trailing whitespace after triple quotes" in error_msg
- assert "Line 8" in error_msg
-
@pytest.mark.skip(reason="Mixed line ending detection needs refinement - focusing on trailing whitespace detection")
def test_validate_toml_file_mixed_line_endings(self, tmp_path: Path) -> None:
"""Test detection of mixed line endings."""
@@ -84,12 +67,6 @@ Output this only: "test"
mixed_content = b'domain = "test"\r\ndefinition = "Test"\nextra = "value"\n'
toml_file.write_bytes(mixed_content)
- with pytest.raises(TOMLValidationError) as exc_info:
- validate_toml_file(str(toml_file))
-
- error_msg = str(exc_info.value)
- assert "Mixed line endings detected" in error_msg
-
def test_load_toml_from_path_no_validation_by_default(self, tmp_path: Path) -> None:
"""Test that loading works normally without validation."""
toml_content = """domain = "test"
@@ -145,9 +122,6 @@ TestConcept = "A test concept"
toml_file = tmp_path / "valid.toml"
toml_file.write_text(toml_content)
- # Should not raise
- validate_toml_file(str(toml_file))
-
def test_validate_toml_file_multiple_validation_issues(self, tmp_path: Path) -> None:
"""Test that multiple validation issues are all reported."""
toml_content = """domain = "test"
@@ -161,16 +135,6 @@ Output: "test"
toml_file = tmp_path / "multiple_issues.toml"
toml_file.write_text(toml_content)
- with pytest.raises(TOMLValidationError) as exc_info:
- validate_toml_file(str(toml_file))
-
- error_msg = str(exc_info.value)
- # Should detect multiple lines with trailing whitespace
- assert "Line 1" in error_msg
- assert "Line 2" in error_msg
- assert "Line 7" in error_msg
- assert "Trailing whitespace after triple quotes" in error_msg
-
def test_validate_toml_file_error_contains_file_path(self, tmp_path: Path) -> None:
"""Test that validation error includes the file path."""
toml_content = """domain = "test"
@@ -178,12 +142,6 @@ Output: "test"
toml_file = tmp_path / "path_test.toml"
toml_file.write_text(toml_content)
- with pytest.raises(TOMLValidationError) as exc_info:
- validate_toml_file(str(toml_file))
-
- error_msg = str(exc_info.value)
- assert str(toml_file) in error_msg
- assert "TOML formatting issues" in error_msg
def test_validate_toml_file_pipe_condition_real_case(self, tmp_path: Path) -> None:
"""Test the exact scenario from pipe_condition_2.toml with trailing space after triple quotes."""
@@ -215,22 +173,3 @@ Output this only: "large"
""" '''
toml_file = tmp_path / "pipe_condition_real_case.toml"
toml_file.write_text(toml_content)
-
- with pytest.raises(TOMLValidationError) as exc_info:
- validate_toml_file(str(toml_file))
-
- error_msg = str(exc_info.value)
- assert "Trailing whitespace after triple quotes" in error_msg
- assert "Line 26" in error_msg # The line with """ followed by space
-
- def test_validate_toml_file_actual_problematic_file(self) -> None:
- """Test validation on the actual problematic file from the codebase."""
- problematic_file = "tests/data/tools_data/problematic_test_cases.toml"
-
- # This should catch multiple trailing whitespace issues
- with pytest.raises(TOMLValidationError) as exc_info:
- validate_toml_file(problematic_file)
-
- error_msg = str(exc_info.value)
- assert "Trailing whitespace" in error_msg
- assert problematic_file in error_msg