How to enrich a company from a domain (Python + LLM workflow) A developer published a Python workflow for enriching company profiles from a domain name, combining Firecrawl for page fetching with OpenAI structured outputs for field extraction. The pipeline normalizes the domain, scrapes the homepage plus up to three same-domain supporting pages (about, contact, team), and validates extracted fields, with the key lesson being to let the model return null rather than guess missing data. The writeup notes that page discovery, missing data, validation and cost control—not the model—are the hard parts. You have a domain. You want a clean company profile: name, description, industry, socials, contact info, location. Sounds like a one-liner. It isn't, but it's closer than you'd think. The workflow is four steps: fetch the site, extract fields with an LLM, validate the output, and figure out the point where building your own thing stops being worth it. I'll walk through all four with real Python you can run today. Stack: Firecrawl https://docs.firecrawl.dev/api-reference/endpoint/scrape for fetching, OpenAI structured outputs https://developers.openai.com/api/docs/guides/structured-outputs for extraction. Plain HTTP, no SDKs, so you can port it to Node, Go, or whatever you live in. The demo everybody writes: This works beautifully on stripe.com . Then your next record is a parked domain, the one after that hides its address three clicks deep, and the one after that is a JS app that returns an empty shell on the first request. The model is rarely the hard part. Page discovery, missing data, validation, and cost control are. The single most useful mindset shift: make it cheap for the model to be honest. If the page doesn't show a phone number, the right answer is null , not a plausible guess that happens to match the country code. pip install requests python import json import os import re from urllib.parse import urljoin, urlparse import requests FIRECRAWL API KEY = os.environ "FIRECRAWL API KEY" OPENAI API KEY = os.environ "OPENAI API KEY" OPENAI MODEL = os.environ.get "OPENAI MODEL", "gpt-5.5" MAX CHARS PER PAGE = 12000 SUPPORTING PAGE LIMIT = 3 Input is always messier than you want. companyenrich.com , https://companyenrich.com , www.companyenrich.com/ . Clean it up first. php def normalize domain to url value: str - str: value = value.strip if not value.startswith "http://", "https://" : value = "https://" + value parsed = urlparse value return f"{parsed.scheme}://{parsed.netloc}".rstrip "/" Here's a gotcha. Firecrawl's onlyMainContent defaults to true , which strips headers, navs, and footers. Great for reading articles. Terrible for enrichment, because the footer is exactly where social links and contact details live. Set it to False . php def scrape url url: str - dict: response = requests.post "https://api.firecrawl.dev/v1/scrape", headers={ "Authorization": f"Bearer {FIRECRAWL API KEY}", "Content-Type": "application/json", }, json={ "url": url, "formats": "markdown", "links" , "onlyMainContent": False, "removeBase64Images": True, "blockAds": True, }, timeout=60, response.raise for status return response.json "data" The homepage alone usually isn't enough. Use the returned links to find a few supporting pages, same-domain only. php def discover supporting urls home url: str, links: list str - list str : home host = urlparse home url .netloc.replace "www.", "" keywords = "/about", "/company", "/contact", "/locations", "/location", "/team" candidates = for link in links or : href = link if isinstance link, str else link.get "href" or link.get "url" if not href: continue absolute = urljoin home url, href parsed = urlparse absolute host = parsed.netloc.replace "www.", "" path = parsed.path.lower if host == home host and any keyword in path for keyword in keywords : candidates.append absolute.split " " 0 return list dict.fromkeys candidates :SUPPORTING PAGE LIMIT Then stitch it all into one payload for the model: php def fetch company pages domain: str - str: home url = normalize domain to url domain pages = home data = scrape url home url pages.append home url, home data.get "markdown", "" for url in discover supporting urls home url, home data.get "links", : try: page data = scrape url url pages.append url, page data.get "markdown", "" except requests.RequestException: continue sections = for url, markdown in pages: trimmed = markdown or "" :MAX CHARS PER PAGE sections.append f"URL: {url}\n\n{trimmed}" return "\n\n---\n\n".join sections This is the part people get wrong. If your prompt says "return null when the field is missing" but your schema says "name": {"type": "string"} , you've handed the model a contradiction. It has to return a string, so it makes one up. Nullable fields aren't a compromise here, they're the whole point. COMPANY SCHEMA = { "type": "object", "properties": { "name": {"type": "string", "null" }, "domain": {"type": "string", "null" }, "description": {"type": "string", "null" }, "long description": {"type": "string", "null" }, "industry": {"type": "string", "null" }, "founded year": {"type": "integer", "null" }, "headquarters": { "type": "object", "properties": { "city": {"type": "string", "null" }, "country": {"type": "string", "null" }, "full address": {"type": "string", "null" }, }, "required": "city", "country", "full address" , "additionalProperties": False, }, "phone": {"type": "string", "null" }, "email": {"type": "string", "null" }, "social profiles": { "type": "object", "properties": { "linkedin": {"type": "string", "null" }, "x": {"type": "string", "null" }, "facebook": {"type": "string", "null" }, "instagram": {"type": "string", "null" }, "youtube": {"type": "string", "null" }, }, "required": "linkedin", "x", "facebook", "instagram", "youtube" , "additionalProperties": False, }, "evidence urls": {"type": "array", "items": {"type": "string"}}, }, "required": "name", "domain", "description", "long description", "industry", "founded year", "headquarters", "phone", "email", "social profiles", "evidence urls", , "additionalProperties": False, } php def extract company profile page content: str - dict: response = requests.post "https://api.openai.com/v1/chat/completions", headers={ "Authorization": f"Bearer {OPENAI API KEY}", "Content-Type": "application/json", }, json={ "model": OPENAI MODEL, "messages": { "role": "system", "content": "Extract structured company data from the provided website pages. " "Use null when a field is not explicitly visible in the provided content. " "Do not guess phone numbers, email addresses, physical addresses, or social URLs. " "Only include evidence urls that appear in the input." , }, {"role": "user", "content": page content}, , "response format": { "type": "json schema", "json schema": { "name": "company profile", "strict": True, "schema": COMPANY SCHEMA, }, }, }, timeout=120, response.raise for status message = response.json "choices" 0 "message" if message.get "refusal" : raise ValueError f"Model refused extraction: {message 'refusal' }" return json.loads message "content" Structured outputs enforce the shape of the response. They do not make the values true . That's the next step. Cheap checks first. Does the phone look like a phone? Does the LinkedIn URL point to a company page, not a person? Is that X link actually on x.com? When in doubt, null it. PHONE RE = re.compile r"^\+? 0-9 0-9\s .- {6,}$" EMAIL RE = re.compile r"^ ^@\s +@ ^@\s +\. ^@\s +$" def valid url value: str | None - bool: if not value: return False parsed = urlparse value return parsed.scheme in {"http", "https"} and bool parsed.netloc def validate profile profile: dict - dict: if profile.get "phone" and not PHONE RE.match profile "phone" : profile "phone" = None if profile.get "email" and not EMAIL RE.match profile "email" : profile "email" = None socials = profile.get "social profiles", {} linkedin = socials.get "linkedin" if linkedin and "linkedin.com/company" not in linkedin: socials "linkedin" = None x url = socials.get "x" if x url and not any host in x url for host in "x.com/", "twitter.com/" : socials "x" = None for key in "facebook", "instagram", "youtube" : if socials.get key and not valid url socials key : socials key = None profile "social profiles" = socials return profile Conservative on purpose. A null is annoying. A fake phone number in your CRM is a support ticket. php def enrich company from domain domain: str - dict: page content = fetch company pages domain raw profile = extract company profile page content return validate profile raw profile if name == " main ": company = enrich company from domain "companyenrich.com" print json.dumps company, indent=2 Sample output: { "name": "CompanyEnrich", "domain": "companyenrich.com", "description": "API-first B2B data platform for company and people intelligence.", "industry": "B2B data infrastructure", "founded year": null, "headquarters": { "city": "Ankara", "country": "Turkey", "full address": null }, "phone": null, "email": null, "social profiles": { "linkedin": "https://www.linkedin.com/company/companyenrich", "x": null, "facebook": null, "instagram": null, "youtube": null }, "evidence urls": "https://companyenrich.com" } Notice how much is null . That's not failure, that's honesty. The site simply doesn't publish those fields. The biggest DIY mistake is treating missing data as a model bug when the source page just doesn't contain it. | Field | Reliability | Notes | |---|---|---| | Name | High | Usually right there on the homepage | | Description | High | Hero or meta description | | Industry | Medium | Often inferred, flag confidence | | Founded year | Low-medium | Frequently missing | | HQ city | Medium | Footer or contact page | | Full address | Low | Lots of SaaS sites omit it | | Phone / Email | Low | Often hidden behind a form | | | High | Validate company vs personal | | Technologies | Out of scope | Needs a tech-detection source | A website tells you what a company says about itself. It can't reliably give you headcount, revenue, funding, tech stack, or historical changes. For those you need other sources, and that's exactly where DIY extraction ends and production enrichment begins. The first 10 domains feel free. The next 10,000 teach you where the cost actually lives. Give every scrape a status instead of a silent failure: success , blocked , timeout , parked , redirected , empty content . A blocked site and a company-with-no-phone are very different things and should never look the same in your data. For cost control, send the smallest useful set of pages, not the whole site. Good defaults: homepage plus up to 3 supporting pages, 8k-15k chars each, no base64 images, no blog archives. Not "DIY bad, API good." The honest version: Build it once to understand the workflow. Buy it when the workflow becomes infrastructure. If you reach that point, a company enrichment API https://companyenrich.com/product/company-enrichment-api pulls from registries, maps, filings, and tech detection on top of the website, which is what fills the gaps a homepage-only flow never can. Full disclosure: that's the product I work on. Keep it boring. Use public business info for legitimate business workflows. Don't scrape private areas, don't infer sensitive personal attributes, respect robots and rate limits. And separate company-level enrichment from person-level enrichment: a domain identifies a company, it isn't a license to harvest every individual you can find. If you store personal data, loop in your legal team on GDPR/CCPA. null instead of guessing That's the whole thing. The model is the easy part. The validation layer and the build-vs-buy call are what actually decide whether your enrichment is trustworthy. If you build this, drop your null rate in the comments. Curious how different stacks compare. I'm founder of CompanyEnrich https://companyenrich.com , an API-first B2B data platform for company and people intelligence. We spend a lot of time on exactly the messy parts above: page discovery, multi-source enrichment, and validation at volume. If you'd rather not maintain your own extraction stack, that's what we build.