This tutorial will show you how to build a company description generator that takes a company name and country as input and returns comprehensive information about the company using the Linkup API’s structured output feature.

What We’re Building

Our company description generator will:

  • Take a company name and country as input
  • Use Linkup API to search for information about the company
  • Return structured data about the company (description, industry, size, location, etc.)

Building the Generator

1

Define the Schema

Before we start coding, let’s define the schema that specifies what information we want to extract about companies. This schema will be used throughout our implementation:

COMPANY_SCHEMA = {
    "type": "object",
    "properties": {
        "name": {
            "type": "string",
            "description": "The official name of the company"
        },
        "description": {
            "type": "string",
            "description": "A comprehensive description of what the company does"
        },
        "location": {
            "type": "string",
            "description": "Location of company headquarters"
        },
        "companySize": {
            "type": "string",
            "description": "Approximate number of employees"
        },
        "linkedInUrl": {
            "type": "string",
            "description": "Company's LinkedIn profile URL"
        }
    },
    "required": ["name", "description"]
}

This schema defines all the fields we want to extract about a company. The required fields are name, description, and industry, while the rest are optional but provide valuable additional information.

2

Install the SDK

Next, let’s install the Linkup SDK in your preferred language:

pip install linkup-sdk
3

Set Up the Client

Initialize the Linkup client with your API key:

Get your API key

Create a Linkup account for free to get your API key.

from linkup import LinkupClient

client = LinkupClient(api_key="<YOUR_LINKUP_API_KEY>")
4

Create the Query Generator

Create a function to generate the search query:

def generate_query(company_name: str, country: str) -> str:
    query = (
            f"Find detailed information about {company_name} in {country}. "
            "Include their main products/services, industry focus, company size, "
            "and any notable achievements or recent news. Also find their "
            "LinkedIn company page if available."
        )
    return query
5

Complete Implementation

Here’s the complete implementation that puts everything together:

from linkup import LinkupClient
import json
from typing import Dict, Any
from pprint import pprint

# Schema definition (from Step 1)
COMPANY_SCHEMA = {
    "type": "object",
    "properties": {
        "name": {
            "type": "string",
            "description": "The official name of the company"
        },
        "description": {
            "type": "string",
            "description": "A comprehensive description of what the company does"
        },
        "location": {
            "type": "string",
            "description": "Location of company headquarters"
        },
        "companySize": {
            "type": "string",
            "description": "Approximate number of employees"
        },
        "linkedInUrl": {
            "type": "string",
            "description": "Company's LinkedIn profile URL"
        }
    },
    "required": ["name", "description"]
}

# Initialize the client
client = LinkupClient(api_key="<YOUR_LINKUP_API_KEY>")

# Query generator (from Step 4)
def generate_query(company_name: str, country: str) -> str:
    query = (
            f"Find detailed information about {company_name} in {country}. "
            "Include their main products/services, industry focus, company size, "
            "and any notable achievements or recent news. Also find their "
            "LinkedIn company page if available."
        )
    return query

def generate_company_description(company_name: str, country: str) -> Dict[str, Any]:
    """
    Generate a structured description of a company using its name, country.

    Args:
        company_name: Name of the company
        country: Country where the company operates

    Returns:
        Dictionary containing structured company information
    """
    try:
        # Clean input
        company_name = company_name.strip()
        country = country.strip()

        # Generate search query using the function from Step 4
        query = generate_query(company_name, country)

        # Call Linkup API
        response = client.search(
            query=query,
            depth="deep",  # Use deep for more thorough results
            output_type="structured",
            structured_output_schema=json.dumps(COMPANY_SCHEMA)
        )

        return response

    except Exception as e:
        return {
            "error": str(e),
            "company_name": company_name,
            "country": country
        }

# Example usage
if __name__ == "__main__":
    # Example companies
    companies = [
        ("Anthropic", "United States"),
        ("Stripe", "United States"),
        ("OpenAI", "United States")
    ]

    for company_name, country in companies:
        print(f"\nLooking up: {company_name} in {country}")
        result = generate_company_description(company_name, country)
        pprint(result)

How It Works

The company description generator works in three main steps:

  1. Input Processing: The tool takes a company name and country as input and cleans them.
  2. Query Generation: It creates a search query that includes both the company name and country to improve search accuracy.
  3. Structured Output: Uses Linkup’s structured output feature with a comprehensive schema to ensure consistent, well-formatted results.

Possible Enhancements

For a production version, consider adding:

  • Add as much information you have about companies in the queries, to limit ambiguity about which company you are searching for.
  • Implement rate limiting and error handling for API usage.
  • Batch processing to search for multiple companies in parallel if you are enriching a dataset for example.

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