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.

Add strict YYYY-MM-DD date validation to PipeSearchSpec and fix blueprint validator

Louis Choquel414009a125c8
diff --git a/pipelex/builder/pipe/pipe_search_spec.py b/pipelex/builder/pipe/pipe_search_spec.py
index b0f4810e9..418d28860 100644
--- a/pipelex/builder/pipe/pipe_search_spec.py
+++ b/pipelex/builder/pipe/pipe_search_spec.py
@@ -1,3 +1,4 @@
+import re
from typing import TYPE_CHECKING, Literal
from pydantic import Field, field_validator
@@ -31,12 +32,26 @@ class PipeSearchSpec(PipeSpec):
)
prompt: str = Field(description="A finalized search prompt or prompt template: use `$` prefix for inline variables (e.g., `$topic`).")
from_date: str | None = Field(
- default=None, description="Start date filter in ISO 8601 format (YYYY-MM-DD). Only return results from this date onwards."
+ default=None,
+ description="Start date filter in ISO 8601 format (YYYY-MM-DD). Only return results from this date onwards.",
+ )
+ to_date: str | None = Field(
+ default=None,
+ description="End date filter in ISO 8601 format (YYYY-MM-DD). Only return results up to this date.",
)
- to_date: str | None = Field(default=None, description="End date filter in ISO 8601 format (YYYY-MM-DD). Only return results up to this date.")
include_domains: list[str] | None = Field(default=None, description="Restrict search to these domains only (e.g., ['reuters.com', 'bbc.com']).")
exclude_domains: list[str] | None = Field(default=None, description="Exclude results from these domains.")
+ @field_validator("from_date", "to_date", mode="before")
+ @classmethod
+ def validate_date_format(cls, date_value: str | None) -> str | None:
+ if date_value is None:
+ return date_value
+ if not re.fullmatch(r"\d{4}-\d{2}-\d{2}", date_value):
+ msg = f"'{date_value}' is not a valid date (expected YYYY-MM-DD)"
+ raise ValueError(msg)
+ return date_value
+
@field_validator("search_talent", mode="before")
@classmethod
def validate_search_talent(cls, search_talent_value: str) -> SearchTalent:
diff --git a/pipelex/pipe_operators/search/pipe_search_blueprint.py b/pipelex/pipe_operators/search/pipe_search_blueprint.py
index f2920e310..173d4354a 100644
--- a/pipelex/pipe_operators/search/pipe_search_blueprint.py
+++ b/pipelex/pipe_operators/search/pipe_search_blueprint.py
@@ -1,4 +1,4 @@
-from datetime import date
+import re
from typing import Literal
from pydantic import field_validator
@@ -31,11 +31,9 @@ class PipeSearchBlueprint(PipeBlueprint):
def validate_date_format(cls, date_value: str | None) -> str | None:
if date_value is None:
return date_value
- try:
- date.fromisoformat(date_value)
- except ValueError:
+ if not re.fullmatch(r"\d{4}-\d{2}-\d{2}", date_value):
msg = f"'{date_value}' is not a valid ISO 8601 date (expected YYYY-MM-DD)"
- raise ValueError(msg) from None
+ raise ValueError(msg)
return date_value
@override