Overview

The Narada Python SDK uses Pydantic models to define structured output schemas, ensuring consistent and type-safe data extraction from automation tasks.

Using Structured Output

Define your data structure using Pydantic models and pass it to the SDK:
import asyncio
from narada import Narada
from pydantic import BaseModel, Field
from typing import List, Optional

# Define your data structure
class JobListing(BaseModel):
    title: str = Field(description="Job title")
    company: str = Field(description="Company name")
    location: str = Field(description="Job location")
    salary: Optional[str] = Field(description="Salary range if available")
    remote: bool = Field(description="Whether the job is remote")

async def main() -> None:
    async with Narada() as narada:
        window = await narada.open_and_initialize_browser_window()

        # Use structured output to extract job data
        response = await window.dispatch_request(
            prompt='/Operator search for "Python developer" jobs on LinkedIn and extract details of the first job listing',
            output_schema=JobListing
        )

        # Access structured data
        job = response["response"]["structuredOutput"]
        print(f"Found job: {job['title']} at {job['company']}")
        print(f"Location: {job['location']}")
        if job['salary']:
            print(f"Salary: {job['salary']}")
        print(f"Remote: {'Yes' if job['remote'] else 'No'}")

if __name__ == "__main__":
    asyncio.run(main())

Supported Data Types

from pydantic import BaseModel, Field

class UserProfile(BaseModel):
    name: str = Field(description="User's full name")
    age: int = Field(description="User's age")
    email: str = Field(description="User's email address")
    active: bool = Field(description="Whether user is active")

Best Practices

Clear Descriptions

Add descriptive Field annotations to guide data extraction

Type Safety

Use appropriate types and Optional fields for reliable data

Modular Models

Break complex schemas into smaller, reusable models

Validation

Let Pydantic handle data validation automatically
Use structured output whenever you need to extract specific data points from web pages. The SDK will ensure the data matches your schema exactly.