Skip to main content

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 Agent, BrowserEnvironment
from pydantic import BaseModel, Field

# 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: str | None = Field(description="Salary range if available")
    remote: bool = Field(description="Whether the job is remote")

async def main() -> None:
    env = BrowserEnvironment()
    agent = Agent(environment=env)

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

        # Access structured data
        job = response.structured_output
        assert job is not None
        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'}")
    finally:
        await env.close()

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.