Overview

JSON Schema allows you to define the exact structure you want for automation responses, ensuring consistent, parseable data output. This is particularly powerful for data extraction tasks where you need structured information in a specific format. To use JSON Schema, you need to add the responseFormat parameter to your Remote Dispatch request.

Adding JSON Schema to Your Request

Here’s how to add the responseFormat parameter to your remote dispatch request:

curl -X POST 'https://api.narada.ai/fast/v2/remote-dispatch' \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: YOUR_API_KEY' \
  -d '{
    "prompt": "/Operator search for software engineering jobs and count how many results you find",
    "sessionId": "your-session-id",
    "responseFormat": {
      "type": "json_schema",
      "json_schema": {
        "name": "search_count",
        "schema": {
          "type": "object",
          "properties": {
            "count": {
              "type": "integer",
              "description": "Number of search results found"
            }
          }
        }
      }
    }
  }'

Supported Data Types

{
  "type": "string",
  "minLength": 1,
  "maxLength": 100,
  "pattern": "^[A-Za-z0-9]+$",
  "format": "email" // email, date, date-time, uri, etc.
}

Parsing API Responses

When using JSON Schema, the response.text field contains valid JSON that matches your specified schema. You can directly parse this text to get a structured object ready for use in your application.

// API response
const apiResponse = {
  "status": "success",
  "response": {
    "text": "{\"count\": 15}"
  }
};

// Parse the structured data
const structuredData = JSON.parse(apiResponse.response.text);
console.log(structuredData.count); // 15

Next Steps