File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -55,6 +55,10 @@ def _format_tool_param_key_for_error(key: str) -> str:
5555def _prepare_extract_tool_params (params : Mapping [str , Any ]) -> Dict [str , Any ]:
5656 normalized_params = _to_param_dict (params )
5757 schema_value = normalized_params .get ("schema" )
58+ if schema_value is not None and not isinstance (schema_value , (str , MappingABC )):
59+ raise HyperbrowserError (
60+ "Extract tool `schema` must be an object or JSON string"
61+ )
5862 if isinstance (schema_value , str ):
5963 try :
6064 parsed_schema = json .loads (schema_value )
Original file line number Diff line number Diff line change @@ -140,6 +140,35 @@ async def run():
140140 asyncio .run (run ())
141141
142142
143+ def test_extract_tool_runnable_rejects_non_mapping_non_string_schema ():
144+ client = _SyncClient ()
145+ params = {
146+ "urls" : ["https://example.com" ],
147+ "schema" : 123 ,
148+ }
149+
150+ with pytest .raises (
151+ HyperbrowserError , match = "Extract tool `schema` must be an object or JSON string"
152+ ):
153+ WebsiteExtractTool .runnable (client , params )
154+
155+
156+ def test_extract_tool_async_runnable_rejects_non_mapping_non_string_schema ():
157+ client = _AsyncClient ()
158+ params = {
159+ "urls" : ["https://example.com" ],
160+ "schema" : 123 ,
161+ }
162+
163+ async def run ():
164+ await WebsiteExtractTool .async_runnable (client , params )
165+
166+ with pytest .raises (
167+ HyperbrowserError , match = "Extract tool `schema` must be an object or JSON string"
168+ ):
169+ asyncio .run (run ())
170+
171+
143172def test_extract_tool_runnable_serializes_empty_object_data ():
144173 client = _SyncClient (response_data = {})
145174
You can’t perform that action at this time.
0 commit comments