Result Schema

Enforce a specific schema of the result.parsed object for task results using Zod (TypeScript) or Pydantic (Python).

1import { BrowserUseClient } from "browser-use-sdk";
2import { z } from "zod";
3
4const client = new BrowserUseClient();
5
6const TaskOutput = z.object({
7 posts: z.array(
8 z.object({
9 title: z.string(),
10 url: z.string(),
11 }),
12 ),
13});
14
15const task = await client.tasks.createTask({
16 task: "Search for the top 10 Hacker News posts and return the title and url.",
17 schema: TaskOutput,
18});
19
20const result = await task.complete();
21
22for (const post of result.parsed.posts) {
23 console.log(`${post.title} - ${post.url}`);
24}