Content Generation

Generate product descriptions, emails, and copy from structured input in your app.

A very common AI feature is generating text from data your app already has: product descriptions, marketing emails, alt text, meta descriptions, and more.

Feed structured input

Instead of a vague prompt, give Claude the concrete data plus clear rules about tone and length. Structured input yields consistent, on-brand output.

Keep humans in the loop

For public-facing copy, generate a draft and let a person review or edit before it publishes. Claude speeds up the first draft; you keep quality control.

Example

Example Β· javascript
async function describeProduct(product) {
  const res = await client.messages.create({
    model: "claude-opus-4-8",
    max_tokens: 300,
    system: "You write product descriptions for an outdoor gear store. " +
      "Friendly, concrete, 40-60 words, no hype words like 'revolutionary'.",
    messages: [{
      role: "user",
      content: `Write a description for:\n${JSON.stringify(product)}`,
    }],
  });
  return res.content.find((b) => b.type === "text")?.text ?? "";
}

await describeProduct({ name: "TrailLite Tent", weight: "1.8kg", sleeps: 2 });

When to use it

  • Generate unique product descriptions for 500 catalogue items by looping over your database and calling Claude per item.
  • Create personalised welcome emails using each new user's name, plan tier, and signup source as template inputs.
  • Auto-generate SEO meta descriptions for blog posts by passing the title and first paragraph to Claude.

More examples

Product description from structured data

Builds the prompt from product fields and caps max_tokens to enforce a concise output length.

Example Β· javascript
async function generateDescription(product) {
  const prompt = `Write a 50-word e-commerce description for:
Name: ${product.name}
Category: ${product.category}
Key features: ${product.features.join(", ")}`;

  const msg = await client.messages.create({
    model: "claude-haiku-4-5",
    max_tokens: 120,
    messages: [{ role: "user", content: prompt }],
  });
  return msg.content[0].text;
}

Batch generate for multiple items

Loops over a batch of products with missing descriptions and writes each result back to the database.

Example Β· javascript
const products = await db.query("SELECT * FROM products WHERE description IS NULL LIMIT 20");

for (const product of products.rows) {
  const description = await generateDescription(product);
  await db.query("UPDATE products SET description=$1 WHERE id=$2", [description, product.id]);
  // small delay to respect rate limits
  await new Promise(r => setTimeout(r, 200));
}

Generate SEO meta from post content

Uses a system rule to enforce the 160-character SEO limit and slices the output as a final safety net.

Example Β· javascript
async function generateMeta(post) {
  const msg = await client.messages.create({
    model: "claude-haiku-4-5",
    max_tokens: 80,
    system: "Return ONLY the meta description. Max 160 characters. No quotes.",
    messages: [{
      role: "user",
      content: `Title: ${post.title}\n\n${post.excerpt}`
    }],
  });
  return msg.content[0].text.slice(0, 160);
}

Discussion

  • Be the first to comment on this lesson.