15 — Scraping, AI APIs and configurable chatbots
Web data and AI as product features — effective, cheap, and under a contract. The operational layer (Timeout — The maximum time to wait for a response — after it the request fails instead of waiting forever. Without it one slow service can quietly hang the whole app. more in the glossary →, backoff, quotas, resumability) → 14.
Scraping
- An official source first (API — An agreed way for two programs to talk to each other — one asks, the other answers in a set format. Through an API your app connects to outside services (payments, maps, AI). Treat an API key like a password. more in the glossary →, feed, export, Sitemap — A file listing every address of the site, helping search engines find them. New pages reach search engines faster, and language versions get linked together. more in the glossary →); HTML Scraping — Automatically gathering data from websites with a program instead of copying by hand. Powerful for acquiring data, but it needs manners: respect others’ rules (robots.txt), don’t overload the server. more in the glossary → is the last resort.
- Respect the source:
robots.txt/ToS, a reasonable throttle, a truthful User-Agent (→ 09). - A site answers twice — policy and machinery. When
robots.txtallows the read but a bot shield blocks it, identify yourself and ask the owner; never engineer a way around the shield. If the request fails, the source leaves the product. - Tell an IP block from a shield before building anything: 403 here but 200 from another network = the address is blocked (relocate the fetch); 403 from every network = the shield is the point.
- Validate the shape of the result, not the status — selector drift raises an alert, never silent zeros.
- Normalize at the entry point against lookup tables (→ 11); fetch the delta, not the whole catalog; loaders are Idempotency — A property of an operation you can run many times with the same result — no duplication. Key for scripts and events: a re-run doesn’t break data. Like an “ON” switch. more in the glossary → (→ 04).
AI APIs
- An LLM (language model) — An AI model trained on huge amounts of text that understands and generates language — e.g. Claude. Great with unstructured text, but more expensive and less predictable than ordinary code. more in the glossary → only where deterministic code can’t cope (unstructured extraction, classification, summaries) — never for what a Regex (regular expression) — A pattern describing the shape of text, e.g. “three digits, a dash, four digits”, used to search or validate data. Simple, fast and free — where it’s enough, AI is an unnecessary cost. more in the glossary →, SQL — The query language for a database — the way you “ask” the database for data or change it. The universal standard for talking to a database. A badly written query can bog down the whole app. more in the glossary → or a function does.
- Force an output contract: JSON schema / tool use, validation, retry on mismatch. LLM output is untrusted input.
- Cache — A temporarily remembered result, so the same thing isn’t computed again on every request. Speeds the app up, but can be a trap: a stale cache shows old data. more in the glossary → identical inputs; quota every paid call; enrich offline in a checkpointed batch rather than live in a user request. Measure cost and latency per task.
Chatbots
- Persona, scope and rules are configuration (versioned data), not code — tuned without a Deploy — Releasing a new version of the app “live”, where real people use it. It’s the moment a change reaches real people — which is why it happens only on an explicit “deploy”. more in the glossary →.
- Grounded in your data, with the source cited; a safe “I don’t know” instead of invention.
- User and web content are data, never instructions (Prompt injection — An attack on AI: someone weaves a hidden instruction into text to make the assistant act against the rules. If AI reads outside content (emails, pages), treat it as untrusted — otherwise it can be manipulated. more in the glossary →): no side-effect action without confirmation, no leaking the system prompt or secrets.
- A golden set of questions runs like tests on every prompt change.
- A disclaimer and a privacy basis for stored conversations (→ 09).
Anti-patterns
- 🚫 Scraping when an API exists; a full re-scrape every night.
- 🚫 Evading a bot shield the owner put up.
- 🚫 Parsing free prose and hoping for the format.
- 🚫 No cache and no quota on paid calls.
- 🚫 A persona baked into the code; an ungrounded assistant.
- 🚫 Acting on a chat message without confirmation.