File tree Expand file tree Collapse file tree 2 files changed +41
-2
lines changed
Expand file tree Collapse file tree 2 files changed +41
-2
lines changed Original file line number Diff line number Diff line change @@ -104,11 +104,13 @@ def _normalize_extract_schema_mapping(
104104def _prepare_extract_tool_params (params : Mapping [str , Any ]) -> Dict [str , Any ]:
105105 normalized_params = _to_param_dict (params )
106106 schema_value = normalized_params .get ("schema" )
107- if schema_value is not None and not isinstance (schema_value , (str , MappingABC )):
107+ if schema_value is not None and not (
108+ type (schema_value ) is str or isinstance (schema_value , MappingABC )
109+ ):
108110 raise HyperbrowserError (
109111 "Extract tool `schema` must be an object or JSON string"
110112 )
111- if isinstance (schema_value , str ) :
113+ if type (schema_value ) is str :
112114 try :
113115 parsed_schema = json .loads (schema_value )
114116 except HyperbrowserError :
Original file line number Diff line number Diff line change @@ -174,6 +174,43 @@ async def run():
174174 asyncio .run (run ())
175175
176176
177+ def test_extract_tool_runnable_rejects_string_subclass_schema_strings ():
178+ class _SchemaString (str ):
179+ pass
180+
181+ client = _SyncClient ()
182+ params = {
183+ "urls" : ["https://example.com" ],
184+ "schema" : _SchemaString ('{"type":"object"}' ),
185+ }
186+
187+ with pytest .raises (
188+ HyperbrowserError ,
189+ match = "Extract tool `schema` must be an object or JSON string" ,
190+ ):
191+ WebsiteExtractTool .runnable (client , params )
192+
193+
194+ def test_extract_tool_async_runnable_rejects_string_subclass_schema_strings ():
195+ class _SchemaString (str ):
196+ pass
197+
198+ client = _AsyncClient ()
199+ params = {
200+ "urls" : ["https://example.com" ],
201+ "schema" : _SchemaString ('{"type":"object"}' ),
202+ }
203+
204+ async def run ():
205+ await WebsiteExtractTool .async_runnable (client , params )
206+
207+ with pytest .raises (
208+ HyperbrowserError ,
209+ match = "Extract tool `schema` must be an object or JSON string" ,
210+ ):
211+ asyncio .run (run ())
212+
213+
177214def test_extract_tool_runnable_rejects_null_schema_json ():
178215 client = _SyncClient ()
179216 params = {
You can’t perform that action at this time.
0 commit comments