Rzemiosło · The Craft
What is The CraftLevelsGet startedChapters Search Download PLEN
Level 3 · Codex ~2 min read

In one sentence: How to gather web data, delegate tasks to AI and build a chatbot you can steer without a deploy — effectively, cheaply, with a contract.

This chapter in plain terms

A chapter about three powers that drive many products today: pulling data from the web (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 →), delegating tasks to AI, and chatbots. You do them “with a contract”, not by magic.

Scraping — the official source first. If there’s an 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 →, a feed or an export — you take it; manually “tearing off” HTML is a last resort, because it breaks with every redesign of the site. And respect the source: honour robots.txt, don’t flood the server with requests — the goal is data, not a DoS.

A site answers with two voices — and they can disagree. robots.txt is the owner’s policy; an WAF — Web Application Firewall — a shield in front of the app that filters web traffic and blocks suspicious requests (often bots). It’s a machine, not a policy: it can block even when robots.txt allows. When it blocks legitimate reading — identify yourself and ask the owner. more in the glossary → (e.g. Cloudflare) is a machine that doesn’t read your intentions. When the policy allows reading but the shield blocks anyway, the honest move is to identify yourself truthfully and ask the owner for access, not to engineer a workaround. (One curl — A command-line tool that sends a request to an address and shows the server’s response. The simplest proof that a page responds and what exactly it returns — no browser needed. more in the glossary → tells them apart: a 403 from the server but 200 from another network = your address is blocked; a 403 from every network = it’s the shield.)

AI for what ordinary code can’t handle. A 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 → is great at extracting meaning from unstructured text, classifying, summarising. But don’t use it 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 → or 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 → will do — that’s pricier, slower and less certain. And always force the response format (e.g. JSON) instead of parsing prose “on hope”.

A chatbot is a product feature, not a toy. Keep its personality and rules as configuration (a file/database), not hard-wired in code — then you change the tone 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 →. And it must answer from your data (grounding), not from the model’s memory — otherwise it will “confidently” make up a price or a fact.

Example of a threat (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 →): treat content from a user or a web page as data, not commands. If a chatbot blindly executes an instruction hidden in someone else’s text, that someone can steer it against your rules.

Read more: what is web scraping · RAG — grounding AI answers · prompt injection.

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

  1. 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.
  2. Respect the source: robots.txt/ToS, a reasonable throttle, a truthful User-Agent (→ 09).
  3. A site answers twice — policy and machinery. When robots.txt allows 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.
  4. 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.
  5. Validate the shape of the result, not the status — selector drift raises an alert, never silent zeros.
  6. 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

  1. 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.
  2. Force an output contract: JSON schema / tool use, validation, retry on mismatch. LLM output is untrusted input.
  3. 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

  1. 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 →.
  2. Grounded in your data, with the source cited; a safe “I don’t know” instead of invention.
  3. 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.
  4. A golden set of questions runs like tests on every prompt change.
  5. 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.
Chapter deep-dive 15Why these rules, examples and stories from projects — what the core deliberately leaves out.

The canonical doctrine is written in English.