All guides

Developer guide

How can I extract specific fields from a video using my own prompt and JSON schema?

Write a prompt for what you want from a social video and add a JSON Schema for the exact fields your app reads. See the same YouTube Short extracted with the prompt alone and with a schema.

The prompt

Start with the prompt alone

The prompt says what you want from the video, in your own words. Send it with a public post URL and mamitsu watches the video, listens to the audio and reads the caption to answer it.

Without a schema, mamitsu chooses descriptive field names and types from the prompt. Asked about the opening hook and calls to action of a YouTube Short about growing an email list, it returned opening_hook and a list of calls_to_action, each with an action and its context.

Prompt alone
: "${XTRAKT_USER_API_KEY:?Set XTRAKT_USER_API_KEY to your mamitsu API key}"
curl https://usemamitsu.com/api/v1/extract \
  -H "Authorization: Bearer $XTRAKT_USER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "url": "https://www.youtube.com/shorts/PJgY3gVIJeE",
  "prompt": "What does this short video open with to grab attention, and which calls to action does it contain? Give the opening hook as it is said or shown, and each call to action with what it asks the viewer to do."
}'
Response
{
  "extraction_id": "ext_9d7c1ba1-ab4e-418e-888a-761cd440d201",
  "data": {
    "opening_hook": "What if you could keep growing your audience, even if TikTok disappeared tomorrow?",
    "calls_to_action": [
      {
        "action": "Download my free guide",
        "context": "linked in my bio"
      },
      {
        "action": "Check out the video",
        "context": "linked here for 17 more tips"
      },
      {
        "action": "Watch Full Video on YouTube",
        "context": "@HubSpotMarketing"
      },
      {
        "action": "Subscribe",
        "context": "on YouTube"
      }
    ]
  },
  "source": {
    "provider": "youtube",
    "url": "https://www.youtube.com/shorts/PJgY3gVIJeE"
  }
}

Your schema

Add a schema for the fields your app reads

Here is the same Short with the same prompt and a JSON Schema. The schema asks for the hook, a hook_format from a fixed list, and where each call to action appears: spoken, on screen or caption.

The answer follows it: the hook is a question, two calls to action are spoken and one is on screen. Every Short you send with this schema comes back with those fields and labels from the same lists, so your app can group and filter them.

Prompt and schema
: "${XTRAKT_USER_API_KEY:?Set XTRAKT_USER_API_KEY to your mamitsu API key}"
curl https://usemamitsu.com/api/v1/extract \
  -H "Authorization: Bearer $XTRAKT_USER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "url": "https://www.youtube.com/shorts/PJgY3gVIJeE",
  "prompt": "What does this short video open with to grab attention, and which calls to action does it contain? Give the opening hook as it is said or shown, and each call to action with what it asks the viewer to do.",
  "schema": {
    "type": "object",
    "properties": {
      "opening_hook": {
        "type": "string"
      },
      "hook_format": {
        "type": "string",
        "enum": [
          "question",
          "bold claim",
          "promise",
          "story",
          "demonstration",
          "other"
        ]
      },
      "calls_to_action": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "action": {
              "type": "string"
            },
            "where": {
              "type": "string",
              "enum": [
                "spoken",
                "on screen",
                "caption"
              ]
            }
          },
          "required": [
            "action",
            "where"
          ]
        }
      }
    },
    "required": [
      "opening_hook",
      "hook_format",
      "calls_to_action"
    ]
  }
}'
Response
{
  "extraction_id": "ext_6cdc86e5-fbda-48de-94dd-c2a524de9f49",
  "data": {
    "opening_hook": "What if you could keep growing your audience even if TikTok disappeared tomorrow?",
    "hook_format": "question",
    "calls_to_action": [
      {
        "action": "download my free guide linked in my bio",
        "where": "spoken"
      },
      {
        "action": "check out the video linked here for 17 more tips",
        "where": "spoken"
      },
      {
        "action": "Watch Full Video on YouTube @HubSpotMarketing",
        "where": "on screen"
      }
    ]
  },
  "source": {
    "provider": "youtube",
    "url": "https://www.youtube.com/shorts/PJgY3gVIJeE"
  }
}

Which to use

When a schema helps, and when the prompt is enough

Add a schema when the result feeds your code, such as a database table or a dashboard that compares many posts. The field names, types and allowed values stay the same on every call, so your app reads them without guessing.

The prompt alone is enough when a person or an agent reads the answer, or while you try a new question before you settle on fields. Many apps start there, then turn the answer they like into a schema.

Either way, the prompt does the asking: say what to look for and in what order. The schema fixes the shape of the answer.

Another schema

A recipe with amounts and steps

This schema asks a miso udon reel for the dish, the total minutes, each ingredient with its amount and the steps in order. Fields that may have no value in the video, like an amount, allow null.

The JavaScript guide sends it with fetch and shows the full response. The schema rules, such as the supported keywords, are in the API reference.

Recipe schema
{
  "type": "object",
  "properties": {
    "dish": {
      "type": "string"
    },
    "total_minutes": {
      "type": [
        "integer",
        "null"
      ]
    },
    "ingredients": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "amount": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "name",
          "amount"
        ],
        "additionalProperties": false
      }
    },
    "steps": {
      "type": "array",
      "items": {
        "type": "string"
      }
    }
  },
  "required": [
    "dish",
    "total_minutes",
    "ingredients",
    "steps"
  ],
  "additionalProperties": false
}

From an AI client

Agents can send a schema too

The extract tool of the mamitsu MCP server takes the same optional schema. Ask your agent for data in a given shape, or give it your schema, and it gets back JSON your code can read.

Connect an MCP client

How can I extract specific fields from a video using my own prompt and JSON schema? · mamitsu