Skip to content

Commit 3697e2c

Browse files
Merge pull request Pipelex#182 from Pipelex/release/v0.6.3
Release/v0.6.3
2 parents 21c85b3 + d72c5b5 commit 3697e2c

8 files changed

Lines changed: 59 additions & 9 deletions

File tree

.cursor/rules/pipelex.mdc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,4 +443,12 @@ pretty_print(gantt_chart, title="Gantt Chart")
443443
get_pipeline_tracker().output_flowchart()
444444
```
445445

446-
ALWAYS RUN `pipelex validate` when you are finished writing pipelines: This checks for errors. If there are errors, iterate until it works.
446+
# Error Handling & Validation
447+
448+
## Validation Error Handling
449+
450+
- Use `StuffContentValidationError` for handling content validation failures
451+
- Use `format_pydantic_validation_error` to format validation errors consistently
452+
453+
ALWAYS RUN `pipelex validate` when you are finished writing pipelines: This checks for errors. If there are errors, iterate until it works.
454+

AGENTS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ This python >=3.10 code is in the `pipelex` directory.
1515
- Add trailing commas to multi-line lists, dicts, function arguments, and tuples with >2 items (helps with cleaner diffs and prevents syntax errors when adding items)
1616
- All imports inside this repo's packages must be absolute package paths from the root
1717

18+
## Error Handling & Validation
19+
20+
- Use `format_pydantic_validation_error` for consistent error formatting when catching ValidationError
21+
- Implement `StuffContentValidationError` for content validation failures
22+
1823
## Linting & checking
1924

2025
- Run `make lint` -> it runs `ruff check . --fix` to enforce all our linting rules

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## [v0.6.3] - 2025-07-18
4+
5+
### Changed
6+
- Enhanced `Stuff.content_as()` method with improved type validation logic - now attempts model validation when `isinstance` check fails
7+
38
## [v0.6.2] - 2025-07-18
49

510
### Added

CLAUDE.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ This python >=3.10 code is in the `pipelex` directory.
1515
- Add trailing commas to multi-line lists, dicts, function arguments, and tuples with >2 items (helps with cleaner diffs and prevents syntax errors when adding items)
1616
- All imports inside this repo's packages must be absolute package paths from the root
1717

18+
## Error Handling & Validation
19+
20+
- Use `StuffContentValidationError` for type validation failures
21+
- Apply `format_pydantic_validation_error` for formatting validation errors consistently
22+
23+
1824
## Test file structure
1925

2026
- Name test files with `test_` prefix

pipelex/core/stuff.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any, Dict, Optional, Type, Union
22

3-
from pydantic import ConfigDict
3+
from pydantic import ConfigDict, ValidationError
44
from typing_extensions import override
55

66
from pipelex import log
@@ -18,9 +18,9 @@
1818
TextAndImagesContent,
1919
TextContent,
2020
)
21-
from pipelex.exceptions import StuffError
21+
from pipelex.exceptions import StuffContentValidationError, StuffError
2222
from pipelex.tools.misc.string_utils import pascal_case_to_snake_case
23-
from pipelex.tools.typing.pydantic_utils import CustomBaseModel
23+
from pipelex.tools.typing.pydantic_utils import CustomBaseModel, format_pydantic_validation_error
2424

2525

2626
class Stuff(CustomBaseModel):
@@ -106,9 +106,25 @@ def is_number(self) -> bool:
106106

107107
def content_as(self, content_type: Type[StuffContentType]) -> StuffContentType:
108108
"""Get content with proper typing if it's of the expected type."""
109-
if not isinstance(self.content, content_type):
110-
raise TypeError(f"Content is of type '{type(self.content)}', instead of the expected '{content_type}'")
111-
return self.content
109+
# First try the direct isinstance check for performance
110+
if isinstance(self.content, content_type):
111+
return self.content
112+
113+
# If isinstance failed, try model validation approach
114+
try:
115+
# Check if class names match (quick filter before attempting validation)
116+
if type(self.content).__name__ == content_type.__name__:
117+
content_dict = self.content.smart_dump()
118+
validated_content = content_type.model_validate(content_dict)
119+
log.debug(f"Model validation passed: converted {type(self.content).__name__} to {content_type.__name__}")
120+
return validated_content
121+
except ValidationError as exc:
122+
formatted_error = format_pydantic_validation_error(exc)
123+
raise StuffContentValidationError(
124+
original_type=type(self.content).__name__, target_type=content_type.__name__, validation_error=formatted_error
125+
) from exc
126+
127+
raise TypeError(f"Content is of type '{type(self.content)}', instead of the expected '{content_type}'")
112128

113129
def as_list_content(self) -> ListContent: # pyright: ignore[reportMissingTypeArgument, reportUnknownParameterType]
114130
"""Get content as ListContent with items of any type."""

pipelex/exceptions.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@ class StuffError(PipelexError):
157157
pass
158158

159159

160+
class StuffContentValidationError(StuffError):
161+
"""Raised when content validation fails during type conversion."""
162+
163+
def __init__(self, original_type: str, target_type: str, validation_error: str):
164+
self.original_type = original_type
165+
self.target_type = target_type
166+
self.validation_error = validation_error
167+
super().__init__(f"Failed to validate content from {original_type} to {target_type}: {validation_error}")
168+
169+
160170
class PipeExecutionError(PipelexError):
161171
pass
162172

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "pipelex"
3-
version = "0.6.2"
3+
version = "0.6.3"
44
description = "Pipelex is an open-source dev tool based on a simple declarative language that lets you define replicable, structured, composable LLM pipelines."
55
authors = [{ name = "Evotis S.A.S.", email = "evotis@pipelex.com" }]
66
maintainers = [{ name = "Pipelex staff", email = "oss@pipelex.com" }]

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)