Skip to content

Commit 677bff5

Browse files
authored
[chore]: strengthen regex validation on act, observe for elementId (#1614)
# why Stricter validation on LLM responses for chosen elementId to interact with # what changed V3 includes **only** elementIds in the shape `number-number` to account for iframe ordinals. This PR ensures the LLMs have stricter validation on the elementId generation by changing the observe and act schemas to to enforce ```typescript z.string().regex(/^\d+-\d+$/) ``` # test plan - [x] act evals - [x] observe evals - [x] combination evals - [x] regression evals <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Enforce 'number-number' format for elementId in observe and act via regex (^\d+-\d+$) to prevent invalid IDs. Aligns with Linear STG-675 guardrail requirements for elementId formatting. <sup>Written for commit 3b70cc1. Summary will update on new commits. <a href="https://cubic.dev/pr/browserbase/stagehand/pull/1614">Review in cubic</a></sup> <!-- End of auto-generated description by cubic. -->
1 parent bdd8b4e commit 677bff5

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

.changeset/clean-birds-fetch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@browserbasehq/stagehand": patch
3+
---
4+
5+
Enforce <number>-<number> regex validation on act/observe for elementId

packages/core/lib/inference.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ export async function observe({
245245
z.object({
246246
elementId: z
247247
.string()
248+
.regex(/^\d+-\d+$/)
248249
.describe(
249250
"the ID string associated with the element. Never include surrounding square brackets. This field must follow the format of 'number-number'.",
250251
),
@@ -382,6 +383,7 @@ export async function act({
382383
const actSchema = z.object({
383384
elementId: z
384385
.string()
386+
.regex(/^\d+-\d+$/)
385387
.describe(
386388
"the ID string associated with the element. Never include surrounding square brackets. This field must follow the format of 'number-number'.",
387389
),

0 commit comments

Comments
 (0)