> ## Documentation Index
> Fetch the complete documentation index at: https://browseruse-0aece648-codex-api-v4-agent-docs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Structured output

> Ask for JSON, then validate the V4 run result in your application.

V4 returns the agent's final answer as a string in `run.result`. Ask the agent for JSON only, then validate it with Pydantic or Zod in your application.

<Note>
  V4 does not currently accept an `output_schema` / `outputSchema` request field. Validation happens client-side.
</Note>

<CodeGroup>
  ```python Python theme={null}
  from browser_use_sdk.v4 import AsyncBrowserUse
  from pydantic import BaseModel

  class Post(BaseModel):
      name: str
      points: int
      comments: int

  class HNPosts(BaseModel):
      posts: list[Post]

  client = AsyncBrowserUse()
  created = await client.runs.create(
      """
      List the top 20 Hacker News posts.
      Return JSON only in this shape:
      {"posts": [{"name": "string", "points": 0, "comments": 0}]}
      """
  )
  run = await client.runs.wait_for_completion(created.id)
  posts = HNPosts.model_validate_json(run.result or "{}")

  for post in posts.posts:
      print(f"{post.name} ({post.points} pts)")
  ```

  ```typescript TypeScript theme={null}
  import { BrowserUse } from "browser-use-sdk/v4";
  import { z } from "zod";

  const HNPosts = z.object({
    posts: z.array(z.object({
      name: z.string(),
      points: z.number(),
      comments: z.number(),
    })),
  });

  const client = new BrowserUse();
  const created = await client.runs.create({
    task: `
      List the top 20 Hacker News posts.
      Return JSON only in this shape:
      {"posts": [{"name": "string", "points": 0, "comments": 0}]}
    `,
  });
  const run = await client.runs.waitForCompletion(created.id);
  const posts = HNPosts.parse(JSON.parse(run.result ?? "{}"));

  for (const post of posts.posts) {
    console.log(`${post.name} (${post.points} pts)`);
  }
  ```
</CodeGroup>

For strict production flows, handle JSON parse or validation failures and retry with a follow-up message that includes the validation error.
