You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
extract() can return element IDs instead of URLs in plain string fields #3234
Extracting links into plain z.string() fields can return internal accessibility-tree element IDs instead of destination URLs. The extraction succeeds because these IDs are valid strings.
Reproduction
With an initialized TypeScript Stagehand instance:
import{z}from"zod/v4";awaitpage.goto("https://news.ycombinator.com/");constresult=awaitstagehand.extract("Extract the first story title and its destination URL",z.object({title: z.string(),url: z.string()}),{ page },);console.log(result.data);
Also try:
constresult=awaitstagehand.extract("Extract the first 5 story destination URLs, separated by newlines",z.object({stories: z.string()}),{ page },);console.log(result.data);
The failure depends on the model returning element IDs. Exact IDs vary with the snapshot.
Actual behavior
Observed URL fields contained values such as "0-74" and "0-112". A multiline string contained:
Requested destination URLs should resolve to the links' actual hrefs, including when the schema uses plain strings.
URL-validated fields such as z.url() should continue working. Unrelated text resembling an ID, such as a score of "3-2", should remain unchanged.
Technical details
The extraction prompt requests link element IDs, but the extraction service resolves them through the snapshot URL map only for schema paths recognized as URL fields. Plain string fields bypass that resolution.
Root cause:transformSchema (packages/extension/utils.ts) only maps schema fields that carry a URL check (z.url()) to element IDs and records their paths. The extract prompt tells the model to answer link requests with element IDs for every schema. A plain z.string() therefore gets the ID instruction but is never resolved through combinedUrlMap, so the ID comes back as the value. I reproduced this against extractService.extract() with a mocked LLM and a fake snapshot.
Plan:
Add a post-processing step in the extract service. It resolves string values that are exactly an element ID (0-74 or [0-74], including newline- or comma-separated lists) through combinedUrlMap. Strings that aren't in the map, such as a score like 3-2, stay unchanged.
Leave z.url() handling as it is.
Add regression tests with mocked LLM responses in packages/extension/tests/extract.test.ts, plus a patch changeset for the extension and the SDKs that bundle it.
Happy to adjust the approach if you'd prefer the fix elsewhere.
Activity
RachitaPant commentedon Oct 22, 2026
Hi, I'd like to take this one.
Root cause:
transformSchema(packages/extension/utils.ts) only maps schema fields that carry a URL check (z.url()) to element IDs and records their paths. The extract prompt tells the model to answer link requests with element IDs for every schema. A plainz.string()therefore gets the ID instruction but is never resolved throughcombinedUrlMap, so the ID comes back as the value. I reproduced this againstextractService.extract()with a mocked LLM and a fake snapshot.Plan:
0-74or[0-74], including newline- or comma-separated lists) throughcombinedUrlMap. Strings that aren't in the map, such as a score like3-2, stay unchanged.z.url()handling as it is.packages/extension/tests/extract.test.ts, plus a patch changeset for the extension and the SDKs that bundle it.Happy to adjust the approach if you'd prefer the fix elsewhere.