File tree Expand file tree Collapse file tree 6 files changed +49
-9
lines changed Expand file tree Collapse file tree 6 files changed +49
-9
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " stagehand " : patch
3
+ ---
4
+
5
+ Fix parsing schema for extract with no arguments (full page extract)
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ # Define source directories (adjust as needed)
4
+ SOURCE_DIRS=" stagehand"
5
+
6
+ # Apply Black formatting first
7
+ echo " Applying Black formatting..."
8
+ black $SOURCE_DIRS
9
+
10
+ # Apply Ruff with autofix for all issues (including import sorting)
11
+ echo " Applying Ruff autofixes (including import sorting)..."
12
+ ruff check --fix $SOURCE_DIRS
13
+
14
+ echo " Checking for remaining issues..."
15
+ ruff check $SOURCE_DIRS
16
+
17
+ echo " Done! Code has been formatted and linted."
Original file line number Diff line number Diff line change 7
7
from stagehand .a11y .utils import get_accessibility_tree
8
8
from stagehand .llm .inference import extract as extract_inference
9
9
from stagehand .metrics import StagehandFunctionName # Changed import location
10
- from stagehand .types import DefaultExtractSchema , ExtractOptions , ExtractResult
10
+ from stagehand .types import (
11
+ DefaultExtractSchema ,
12
+ EmptyExtractSchema ,
13
+ ExtractOptions ,
14
+ ExtractResult ,
15
+ )
11
16
from stagehand .utils import inject_urls , transform_url_strings_to_ids
12
17
13
18
T = TypeVar ("T" , bound = BaseModel )
@@ -166,4 +171,6 @@ async def _extract_page_text(self) -> ExtractResult:
166
171
167
172
tree = await get_accessibility_tree (self .stagehand_page , self .logger )
168
173
output_string = tree ["simplified" ]
169
- return ExtractResult (data = output_string )
174
+ output_dict = {"page_text" : output_string }
175
+ validated_model = EmptyExtractSchema .model_validate (output_dict )
176
+ return ExtractResult (data = validated_model ).data
Original file line number Diff line number Diff line change 16
16
ObserveOptions ,
17
17
ObserveResult ,
18
18
)
19
- from .types import DefaultExtractSchema
19
+ from .types import DefaultExtractSchema , EmptyExtractSchema
20
20
21
21
_INJECTION_SCRIPT = None
22
22
@@ -361,12 +361,17 @@ async def extract(
361
361
processed_data_payload = result_dict
362
362
if schema_to_validate_with and isinstance (processed_data_payload , dict ):
363
363
try :
364
- validated_model = schema_to_validate_with .model_validate (
365
- processed_data_payload
366
- )
367
- processed_data_payload = (
368
- validated_model # Payload is now the Pydantic model instance
369
- )
364
+ # For extract with no params
365
+ if not options_obj :
366
+ validated_model = EmptyExtractSchema .model_validate (
367
+ processed_data_payload
368
+ )
369
+ processed_data_payload = validated_model
370
+ else :
371
+ validated_model = schema_to_validate_with .model_validate (
372
+ processed_data_payload
373
+ )
374
+ processed_data_payload = validated_model
370
375
except Exception as e :
371
376
self ._stagehand .logger .error (
372
377
f"Failed to validate extracted data against schema { schema_to_validate_with .__name__ } : { e } . Keeping raw data dict in .data field."
Original file line number Diff line number Diff line change 23
23
ActOptions ,
24
24
ActResult ,
25
25
DefaultExtractSchema ,
26
+ EmptyExtractSchema ,
26
27
ExtractOptions ,
27
28
ExtractResult ,
28
29
MetadataSchema ,
56
57
"AgentConfig" ,
57
58
"AgentExecuteOptions" ,
58
59
"AgentResult" ,
60
+ "EmptyExtractSchema" ,
59
61
]
Original file line number Diff line number Diff line change @@ -9,6 +9,10 @@ class DefaultExtractSchema(BaseModel):
9
9
extraction : str
10
10
11
11
12
+ class EmptyExtractSchema (BaseModel ):
13
+ page_text : str
14
+
15
+
12
16
class ObserveElementSchema (BaseModel ):
13
17
element_id : int
14
18
description : str = Field (
You can’t perform that action at this time.
0 commit comments