Linkup’s structured output feature allows you to receive responses in a custom format that you define. This is particularly useful when you need to integrate Linkup’s responses directly into your application’s data structure or when you want to ensure consistency in the response format.

How It Works

To use structured outputs:

  1. Set outputType to structured in your API request
  2. Provide a JSON schema in the structuredOutputSchema parameter
  3. The API will return a response that strictly follows your schema

Basic Example

Let’s start with a simple example that extracts company classification information:

curl --request POST \
  --url https://api.linkup.so/v1/search \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "q": "Please classify Tesla Inc. based on its primary business focus: is it primarily an automotive company, an energy company, or a technology company? Justify your answer.",
  "depth": "deep",
  "outputType": "structured",
  "structuredOutputSchema": {
    "type": "object",
    "properties": {
      "primaryCategory": {
        "type": "string",
        "enum": ["automotive", "energy", "technology"]
      },
      "justification": {
        "type": "string"
      }
    }
  }
}'

Example response:

{
  "primaryCategory": "automotive",
  "justification": "While Tesla is involved in energy solutions and technology development, its primary revenue stream and core business operations revolve around the design, manufacturing, and sale of electric vehicles."
}

Advanced Example: Competitive Analysis

This example shows how to extract structured competitive analysis information:

curl --request POST \
  --url https://api.linkup.so/v1/search \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "q": "Compare Apple, Samsung, and Xiaomi in the smartphone market, focusing on their market share, global revenue, key strengths, and primary challenges.",
  "outputType": "structured",
  "depth": "deep",
  "structuredOutputSchema": {
    "type": "object",
    "properties": {
      "companies": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "name": {
              "type": "string"
            },
            "marketPosition": {
              "type": "object",
              "properties": {
                "globalMarketShare": {
                  "type": "number"
                },
                "rankingByRevenue": {
                  "type": "integer"
                }
              }
            },
            "strengths": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "challenges": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        }
      },
      "marketOverview": {
        "type": "string"
      }
    }
  }
}'

Example response:

{
  "companies": [
    {
      "name": "Apple",
      "marketPosition": {
        "globalMarketShare": 17.2,
        "rankingByRevenue": 1
      },
      "strengths": [
        "Strong brand loyalty",
        "Premium pricing power",
        "Integrated ecosystem"
      ],
      "challenges": [
        "Market saturation",
        "Strong competition in emerging markets",
        "Supply chain dependencies"
      ]
    },
    {
      "name": "Samsung",
      "marketPosition": {
        "globalMarketShare": 20.1,
        "rankingByRevenue": 2
      },
      "strengths": [
        "Diverse product portfolio",
        "Vertical integration",
        "Strong presence in emerging markets"
      ],
      "challenges": [
        "Intense competition at all price points",
        "Margin pressure in mid-range segment",
        "Brand perception vs Apple in premium segment"
      ]
    }
  ],
  "marketOverview": "The smartphone market continues to be highly competitive with a focus on 5G capabilities and AI integration. Premium segment shows steady growth while mid-range experiences intense competition."
}

Best Practices

  1. Schema Design:

    • Keep your schema as simple as possible while meeting your needs
    • Add descriptions to the fields to limit ambiguity
    • Use appropriate data types (string, number, boolean, etc.)
    • When in doubt, refer to the JSON documentation
  2. Query Formulation:

    • Write your query so that the answer to it should contain the information requested in the structured output- the system will use the query response to fill the output
    • Provide clear context in your query and use explicit instructions

Common Use Cases

  • Company classification and categorization
  • Competitive analysis
  • Market research
  • Product comparisons
  • Company performance assessments

Facing issues? Reach out to our engineering team at support@linkup.so