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.

Harden spec parsing: default field type to text, unify pipe_code alias handling

Louis Choquel6f0dd107c5aa
diff --git a/pipelex/builder/operations/concept_ops.py b/pipelex/builder/operations/concept_ops.py
index 9be3ea6b5..10736bb31 100644
--- a/pipelex/builder/operations/concept_ops.py
+++ b/pipelex/builder/operations/concept_ops.py
@@ -50,6 +50,9 @@ def parse_concept_spec(spec_data: dict[str, Any]) -> ConceptSpec:
# Full field spec — copy to avoid mutating nested caller data
field_data = dict(field_data)
field_data["the_field_name"] = field_name
+ # Default to "text" when agent omits the type field
+ if "type" not in field_data:
+ field_data["type"] = "text"
converted_structure[field_name] = field_data
spec_data["structure"] = converted_structure
diff --git a/pipelex/builder/operations/pipe_ops.py b/pipelex/builder/operations/pipe_ops.py
index 4be863635..8c3497658 100644
--- a/pipelex/builder/operations/pipe_ops.py
+++ b/pipelex/builder/operations/pipe_ops.py
@@ -23,6 +23,19 @@ from pipelex.builder.pipe.pipe_sequence_spec import PipeSequenceSpec
from pipelex.builder.pipe.pipe_spec import PipeSpec
from pipelex.builder.pipe.pipe_spec_map import pipe_type_to_spec_class
+# Aliases that agents may use instead of "pipe_code" — checked in order, first match wins.
+_PIPE_CODE_ALIASES = ("pipe", "the_pipe_code", "code", "name", "pipe_name", "pipe_ref")
+
+
+def _normalize_pipe_code_aliases(data: dict[str, Any]) -> None:
+ """Convert any alias of ``pipe_code`` to the canonical field name, in-place."""
+ for alias in _PIPE_CODE_ALIASES:
+ if alias in data:
+ if "pipe_code" not in data:
+ data["pipe_code"] = data.pop(alias)
+ else:
+ data.pop(alias)
+
def parse_pipe_spec(pipe_type: str, spec_data: dict[str, Any]) -> PipeSpec:
"""Parse and validate a PipeSpec from JSON-like data.
@@ -51,22 +64,16 @@ def parse_pipe_spec(pipe_type: str, spec_data: dict[str, Any]) -> PipeSpec:
# Add type to spec_data if not present
spec_data["type"] = pipe_type
- # Accept common aliases for "pipe_code"
- for alias in ("the_pipe_code", "code", "name", "pipe_name", "pipe_ref"):
- if alias in spec_data:
- if "pipe_code" not in spec_data:
- spec_data["pipe_code"] = spec_data.pop(alias)
- else:
- spec_data.pop(alias)
+ # Accept common aliases for "pipe_code" at the top level
+ _normalize_pipe_code_aliases(spec_data)
- # Handle steps/branches conversion - need to convert pipe to pipe_code
+ # Handle steps/branches conversion — apply the same alias normalization
# Deep-copy nested dicts to avoid mutating caller's nested structures
if "steps" in spec_data:
converted_steps = []
for step in spec_data["steps"]:
step = dict(step)
- if "pipe" in step and "pipe_code" not in step:
- step["pipe_code"] = step.pop("pipe")
+ _normalize_pipe_code_aliases(step)
converted_steps.append(step)
spec_data["steps"] = converted_steps
@@ -74,8 +81,7 @@ def parse_pipe_spec(pipe_type: str, spec_data: dict[str, Any]) -> PipeSpec:
converted_branches = []
for branch in spec_data["branches"]:
branch = dict(branch)
- if "pipe" in branch and "pipe_code" not in branch:
- branch["pipe_code"] = branch.pop("pipe")
+ _normalize_pipe_code_aliases(branch)
converted_branches.append(branch)
spec_data["branches"] = converted_branches
diff --git a/tests/unit/pipelex/builder/operations/test_parse_concept_spec.py b/tests/unit/pipelex/builder/operations/test_parse_concept_spec.py
index 95970259f..d38eec3ef 100644
--- a/tests/unit/pipelex/builder/operations/test_parse_concept_spec.py
+++ b/tests/unit/pipelex/builder/operations/test_parse_concept_spec.py
@@ -64,6 +64,24 @@ class TestParseConceptSpec:
assert result.structure["title"].type == ConceptStructureSpecFieldType.TEXT
assert result.structure["title"].description == "The title of the item"
+ def test_dict_field_without_type_defaults_to_text(self) -> None:
+ """When agent provides a dict field spec but omits 'type', it should default to text."""
+ spec: dict[str, Any] = {
+ "concept_code": "MatchAnalysis",
+ "description": "Analysis of CV-job match",
+ "structure": {
+ "matching_strengths": {"description": "Key areas where CV aligns", "required": True},
+ "gaps": {"description": "Areas where CV falls short", "required": True},
+ "summary": {"description": "Brief overall assessment"},
+ },
+ }
+ result = parse_concept_spec(spec)
+ assert result.structure is not None
+ for field_name in ("matching_strengths", "gaps", "summary"):
+ assert result.structure[field_name].type == ConceptStructureSpecFieldType.TEXT
+ assert result.structure["matching_strengths"].required is True
+ assert result.structure["summary"].required is False
+
def test_mixed_string_and_dict_fields(self) -> None:
spec: dict[str, Any] = {
"concept_code": "Mixed",
diff --git a/tests/unit/pipelex/builder/operations/test_parse_pipe_spec.py b/tests/unit/pipelex/builder/operations/test_parse_pipe_spec.py
index 716aa170d..f88b5cf14 100644
--- a/tests/unit/pipelex/builder/operations/test_parse_pipe_spec.py
+++ b/tests/unit/pipelex/builder/operations/test_parse_pipe_spec.py
@@ -135,6 +135,43 @@ class TestParsePipeSpec:
assert result.branches[0].pipe_code == "branch_a"
assert result.branches[1].pipe_code == "branch_b"
+ @pytest.mark.parametrize("alias", ["pipe_ref", "the_pipe_code", "code", "name", "pipe_name"])
+ def test_sequence_steps_all_aliases(self, alias: str) -> None:
+ """All pipe_code aliases must work inside step dicts, not just 'pipe'."""
+ spec: dict[str, Any] = {
+ "pipe_code": "my_seq",
+ "description": "A sequence",
+ "inputs": {"doc": "Document"},
+ "output": "Text",
+ "steps": [
+ {alias: "step_one", "result": "intermediate"},
+ {alias: "step_two", "result": "final"},
+ ],
+ }
+ result = parse_pipe_spec("PipeSequence", spec)
+ assert isinstance(result, PipeSequenceSpec)
+ assert result.steps[0].pipe_code == "step_one"
+ assert result.steps[1].pipe_code == "step_two"
+
+ @pytest.mark.parametrize("alias", ["pipe_ref", "the_pipe_code", "code", "name", "pipe_name"])
+ def test_parallel_branches_all_aliases(self, alias: str) -> None:
+ """All pipe_code aliases must work inside branch dicts, not just 'pipe'."""
+ spec: dict[str, Any] = {
+ "pipe_code": "my_par",
+ "description": "Parallel branches",
+ "inputs": {"doc": "Document"},
+ "output": "Text",
+ "add_each_output": True,
+ "branches": [
+ {alias: "branch_a", "result": "result_a"},
+ {alias: "branch_b", "result": "result_b"},
+ ],
+ }
+ result = parse_pipe_spec("PipeParallel", spec)
+ assert isinstance(result, PipeParallelSpec)
+ assert result.branches[0].pipe_code == "branch_a"
+ assert result.branches[1].pipe_code == "branch_b"
+
# -- PipeCondition expression alias -----------------------------------
_BASE_CONDITION: ClassVar[dict[str, Any]] = {