Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

fix(python-sdk): loosen tbs validation to allow sbd:1 and combined values (#2899)

firecrawl-spring[bot]b65b637e87d7
diff --git a/apps/python-sdk/firecrawl/__init__.py b/apps/python-sdk/firecrawl/__init__.py
index 1120f0106..2b95b22de 100644
--- a/apps/python-sdk/firecrawl/__init__.py
+++ b/apps/python-sdk/firecrawl/__init__.py
@@ -17,7 +17,7 @@ from .v1 import (
V1ChangeTrackingOptions,
)
-__version__ = "4.16.1"
+__version__ = "4.16.2"
# Define the logger for the Firecrawl project
logger: logging.Logger = logging.getLogger("firecrawl")
diff --git a/apps/python-sdk/firecrawl/__tests__/unit/v2/methods/test_search_validation.py b/apps/python-sdk/firecrawl/__tests__/unit/v2/methods/test_search_validation.py
index 242469573..406fdde49 100644
--- a/apps/python-sdk/firecrawl/__tests__/unit/v2/methods/test_search_validation.py
+++ b/apps/python-sdk/firecrawl/__tests__/unit/v2/methods/test_search_validation.py
@@ -79,45 +79,29 @@ class TestSearchValidation:
with pytest.raises(ValueError, match="Location must be a non-empty string"):
_validate_search_request(request)
- def test_validate_invalid_tbs(self):
- """Test validation of invalid tbs values."""
- invalid_tbs_values = ["invalid", "qdr:x", "yesterday", "last_week"]
-
- for invalid_tbs in invalid_tbs_values:
- request = SearchRequest(query="test", tbs=invalid_tbs)
- with pytest.raises(ValueError, match="Invalid tbs value"):
+ def test_validate_empty_tbs(self):
+ """Test validation rejects empty tbs values."""
+ for empty_tbs in ["", " "]:
+ request = SearchRequest(query="test", tbs=empty_tbs)
+ with pytest.raises(ValueError, match="tbs must be a non-empty string"):
_validate_search_request(request)
- def test_validate_custom_date_ranges(self):
- """Test validation of custom date range formats."""
- valid_custom_ranges = [
+ def test_validate_tbs_passthrough(self):
+ """Test that tbs values are passed through without strict validation."""
+ valid_tbs_values = [
+ "qdr:d",
+ "qdr:w",
+ "sbd:1",
+ "sbd:1,qdr:w",
+ "sbd:1,cdr:1,cd_min:1/1/2024,cd_max:12/31/2024",
"cdr:1,cd_min:1/1/2024,cd_max:12/31/2024",
- "cdr:1,cd_min:12/1/2024,cd_max:12/31/2024",
- "cdr:1,cd_min:2/28/2023,cd_max:3/1/2023",
- "cdr:1,cd_min:10/15/2023,cd_max:11/15/2023"
]
- for valid_range in valid_custom_ranges:
- request = SearchRequest(query="test", tbs=valid_range)
+ for tbs in valid_tbs_values:
+ request = SearchRequest(query="test", tbs=tbs)
validated = _validate_search_request(request)
assert validated == request
- def test_validate_invalid_custom_date_ranges(self):
- """Test validation of invalid custom date range formats."""
- # Invalid custom date ranges
- invalid_custom_ranges = [
- "cdr:1,cd_min:2/28/2023", # Missing cd_max
- "cdr:1,cd_max:2/28/2023", # Missing cd_min
- "cdr:2,cd_min:1/1/2024,cd_max:12/31/2024", # Wrong cdr value
- "cdr:cd_min:1/1/2024,cd_max:12/31/2024", # Missing :1
- "custom:1,cd_min:1/1/2024,cd_max:12/31/2024" # Wrong prefix
- ]
-
- for invalid_range in invalid_custom_ranges:
- request = SearchRequest(query="test", tbs=invalid_range)
- with pytest.raises(ValueError, match="Invalid"):
- _validate_search_request(request)
-
def test_validate_valid_requests(self):
"""Test that valid requests pass validation."""
# Minimal valid request
diff --git a/apps/python-sdk/firecrawl/v2/methods/aio/search.py b/apps/python-sdk/firecrawl/v2/methods/aio/search.py
index 6729d6f93..b32e6dabe 100644
--- a/apps/python-sdk/firecrawl/v2/methods/aio/search.py
+++ b/apps/python-sdk/firecrawl/v2/methods/aio/search.py
@@ -1,4 +1,3 @@
-import re
from typing import Dict, Any, Union, List, TypeVar, Type
from ...types import (
SearchRequest,
@@ -124,18 +123,8 @@ def _validate_search_request(request: SearchRequest) -> SearchRequest:
raise ValueError("Location must be a non-empty string")
if request.tbs is not None:
- valid_tbs_values = {
- "qdr:h", "qdr:d", "qdr:w", "qdr:m", "qdr:y",
- "d", "w", "m", "y"
- }
- if request.tbs in valid_tbs_values:
- pass
- elif request.tbs.startswith("cdr:"):
- custom_date_pattern = r"^cdr:1,cd_min:\d{1,2}/\d{1,2}/\d{4},cd_max:\d{1,2}/\d{1,2}/\d{4}$"
- if not re.match(custom_date_pattern, request.tbs):
- raise ValueError(f"Invalid custom date range format: {request.tbs}. Expected format: cdr:1,cd_min:MM/DD/YYYY,cd_max:MM/DD/YYYY")
- else:
- raise ValueError(f"Invalid tbs value: {request.tbs}. Valid values: {valid_tbs_values} or custom date range format: cdr:1,cd_min:MM/DD/YYYY,cd_max:MM/DD/YYYY")
+ if not isinstance(request.tbs, str) or len(request.tbs.strip()) == 0:
+ raise ValueError("tbs must be a non-empty string")
if request.scrape_options is not None:
validate_scrape_options(request.scrape_options)
diff --git a/apps/python-sdk/firecrawl/v2/methods/search.py b/apps/python-sdk/firecrawl/v2/methods/search.py
index ca434ba6d..733695f01 100644
--- a/apps/python-sdk/firecrawl/v2/methods/search.py
+++ b/apps/python-sdk/firecrawl/v2/methods/search.py
@@ -2,7 +2,6 @@
Search functionality for Firecrawl v2 API.
"""
-import re
from typing import Dict, Any, Union, List, TypeVar, Type
from ..types import SearchRequest, SearchData, Document, SearchResultWeb, SearchResultNews, SearchResultImages
from ..utils.normalize import normalize_document_input, _map_search_result_keys
@@ -150,19 +149,8 @@ def _validate_search_request(request: SearchRequest) -> SearchRequest:
# Validate tbs (time-based search, if provided)
if request.tbs is not None:
- valid_tbs_values = {
- "qdr:h", "qdr:d", "qdr:w", "qdr:m", "qdr:y", # Google time filters
- "d", "w", "m", "y" # Short forms
- }
-
- if request.tbs in valid_tbs_values:
- pass # Valid predefined value
- elif request.tbs.startswith("cdr:"):
- custom_date_pattern = r"^cdr:1,cd_min:\d{1,2}/\d{1,2}/\d{4},cd_max:\d{1,2}/\d{1,2}/\d{4}$"
- if not re.match(custom_date_pattern, request.tbs):
- raise ValueError(f"Invalid custom date range format: {request.tbs}. Expected format: cdr:1,cd_min:MM/DD/YYYY,cd_max:MM/DD/YYYY")
- else:
- raise ValueError(f"Invalid tbs value: {request.tbs}. Valid values: {valid_tbs_values} or custom date range format: cdr:1,cd_min:MM/DD/YYYY,cd_max:MM/DD/YYYY")
+ if not isinstance(request.tbs, str) or len(request.tbs.strip()) == 0:
+ raise ValueError("tbs must be a non-empty string")
# Validate scrape_options (if provided)
if request.scrape_options is not None: