How to Automate Catalog Product Rewriting
Summary
When you need to rewrite hundreds of product cards into a new format, manual work takes weeks. Here is a step-by-step plan for building a pipeline: format research, prompt for LLM, publication via API and result validation. This approach is not only applicable to Webasyst but also to any CMS with API. How it looked in a real project—see the case of 728 cards.
General Idea
The task breaks down into three parts:
- Understand the format—what is there now and what should be.
- Teach the model—write a prompt that outputs text of the strictly required structure.
- Automate the writing—publish the result without manual copying.
The pipeline is assembled from small scripts, each responsible for one stage. This allows debugging in parts and restarting without fear.
Step 1. Investigate Before Writing Code
First, download and analyze two things: the standard (already correctly formatted card) and the old card. Compare them.
import requests
def fetch(url: str) -> str:
r = requests.get(
url,
headers={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"},
timeout=30,
)
r.raise_for_status()
return r.text
etalon = fetch("https://example.com/good-product/")
old = fetch("https://example.com/old-product/")
Find differences:
- header structure (
h2,h3); - CSS classes in blocks (
faq-item,facts-wrapper); - presence or absence of FAQ section;
- format of the short description.
Find Markers
The key step is to highlight markers of the new format. These are classes or strings that can be used to deterministically distinguish between "already done" and "not yet done":
MARKERS = ["faq-item", "faq-item__question", "facts-wrapper"]
def is_new_format(html: str) -> bool:
return any(m in html for m in MARKERS)
Checking by markers is more reliable than "looking with the eyes": it can be run on thousands of pages in minutes.
Step 2. Inventory
Navigate the sitemap and collect a list of all cards with statuses:
import xml.etree.ElementTree as ET
tree = ET.parse("sitemap.xml")
urls = [e.text for e in tree.iter() if e.tag.endswith("loc")]
inventory = []
for url in urls:
html = fetch(url)
inventory.append({
"url": url,
"needs_rewrite": not is_new_format(html),
})
Save the result in CSV or a database. Now you have a queue of tasks.
Step 3. Extract Data for Text
Models need facts: name, SKU, features. You don't need to invent them—take them from the page or from the API CMS.
For Webasyst, this is done through shop.product.getInfo:
data = api_call("shop.product.getInfo", {"id": product_id})
product = data["data"]
facts = {
"name": product["name"],
"summary": product.get("summary", ""),
"features": product.get("features", {}),
}
Features are the source of truth. The prompt should explicitly prohibit the model from going beyond them.
Step 4. Write a Strict Prompt
The prompt should set the output structure as strictly as possible:
You are a catalog editor. Given the product characteristics (JSON)
and the old description.
Generate a new description strictly according to the standard structure:
- introductory paragraph;
- summary of characteristics from JSON;
- block "Main Characteristics" with classes faq-item;
- block "Care Recommendations";
- block "Areas of Application";
- FAQ with 5 questions.
Rules:
- use only facts from JSON;
- classes and order of sections—strictly as in the standard;
- return JSON: {"description_html": "...", "summary_text": "..."}.
Three techniques that sharply increase quality:
- Few-shot—insert the standard completely as an example.
- Strict output format—require JSON, not free text.
- Prohibition on inventing—explicitly write "only facts from input data".
Step 5. Publish via API, Not Browser
If the CMS has an API—use it. Browser automation is slower and more fragile, and the visual editor may clean up non-standard classes.
For Webasyst:
api_call("shop.product.update", {
"id": product_id,
"description": new_html,
"summary": new_summary,
})
Before writing, always save the old description—this is a rollback mechanism:
backup = {
"id": product_id,
"old_description": product["description"],
"old_summary": product.get("summary", ""),
}
save_backup(backup)
Step 6. Validate the Result
After publication, don't take it at face value—recheck. Download the card again and make sure the markers have appeared:
html = fetch(url)
if is_new_format(html):
mark_done(product_id)
else:
mark_error(product_id)
Only after such verification does the status change to "done".
Step 7. Organize Queue and Retries
For mass runs, you need:
- batches—process 50 cards with a pause to catch problems early;
- retries—repeat the request with a pause after a network error;
- rate limit—don't bombard the API with hundreds of requests per second;
- log—write the status of each card to a file or database.
Checklist Before Launch
- standard and old card studied;
- markers of the new format highlighted;
- inventory compiled;
- prompt gives stable JSON;
- old descriptions are saved before replacement;
- validation after posting works;
- there is a rollback and log.