Prompt Engineering  

Prompt Engineering for E-Commerce: CoT, ToT, and GSCP with Real-World Prompts

Executive Overview

E-commerce systems already log rich events and expose robust APIs (catalog, pricing, inventory, OMS, payments). Prompt engineering turns those assets into decision-ready AI: ranking search results, drafting product copy with citations, deciding return eligibility, or proposing a price change within guardrails. This article focuses on how to write production-grade prompts—using Chain-of-Thought (CoT), Tree-of-Thought (ToT), and Gödel’s Scaffolded Cognitive Prompting (GSCP)—with copy-pasteable examples tailored to retail operations.

Ground rules (baked into every prompt):

  1. Think privately; do not reveal step-by-step reasoning.

  2. Output only the requested schema and a brief rationale (≤5 bullets).

  3. Respect privacy/consent flags and policy constraints.

  4. Cite sources (IDs/URLs) when answers depend on retrieval.

Where Prompting Fits in the Commerce Stack

  • Search & Merchandising: query rewrite, candidate rerank, shelf composition, SEO snippets.

  • Pricing & Promotions: elasticity reasoning, guardrailed experiments, offer eligibility.

  • Fraud & Risk: hypothesis generation, evidence summary, triage recommendations.

  • Customer Care Copilot: RAG answers for WISMO/returns/warranty with citations.

  • Content & UGC: PDP copy, size guides, moderation rationales.

  • Ops & Supply: substitution suggestions, promise-date negotiation, exception summaries.

CoT (Chain-of-Thought): Linear Reasoning for Narrow Decisions

When to use: A single best path exists (policy check, small classification, focused rewrite).
Risk control: Ask the model to reason silently and return a short rationale + final decision.

CoT Prompt 1 — Search Query Rewrite (semantic + constraints)

System
You are a retail search rewriter. Think silently. Output JSON only.

User
Rewrite the customer query for retrieval. 
Constraints:
- Keep intent and product type.
- Map brand nicknames to canonical brands.
- Expand attributes to common synonyms.
- No PII. No hallucinated brands.

Inputs:
- raw_query: "{{query}}"
- brand_alias_map_id: "brand-alias-v3"
- attribute_vocab_id: "attr-v2"

Output JSON schema:
{
  "rewritten_query": "string",
  "synonyms_added": ["string"],
  "brand_normalized_to": "string|null",
  "rationale": ["bullet", "..."]  // ≤5 bullets
}

CoT Prompt 2 — Returns Eligibility Decision

System
You are a policy judge. Think silently. Output JSON only.

User
Decide return eligibility per policy RET-30D-NO-WORN.
If unsure, return "manual_review": true.

Inputs:
- order_id: "{{order_id}}"
- item_sku: "{{sku}}"
- purchase_date: "{{purchase_date}}"
- delivered_date: "{{delivered_date}}"
- condition_tag: "{{condition}}"   // new, unused, worn, damaged, sealed
- policy_text_id: "RET-30D-NO-WORN"
- region: "{{region}}"

Output:
{
  "eligible": true|false,
  "reason_code": "OK_WITHIN_WINDOW|OUT_OF_WINDOW|DISALLOWED_CONDITION|REGION_EXEMPTION|NEEDS_REVIEW",
  "manual_review": true|false,
  "rationale": ["≤5 bullets"],
  "citations": ["policy:RET-30D-NO-WORN", "order:{{order_id}}"]
}

CoT Prompt 3 — Accessory Bundle Suggestion (PDP)

System
You compose accessory bundles. Think silently. Output JSON only.

User
Given a base SKU, suggest up to 3 accessories in stock that increase basket margin.
Respect compatibility rules and MAP pricing.

Inputs:
- base_sku: "{{sku}}"
- compatibility_graph_id: "compat-graph-v4"
- inventory_view: "online-now"
- pricing_view: "map-guarded"

Output:
{
  "base_sku": "{{sku}}",
  "suggested": [
    {"sku":"...", "why":["compatibility","review_match","in_stock"]},
    {"sku":"...", "why":["style_match","margin_ok"]}
  ],
  "rationale": ["≤5 bullets"]
}

ToT (Tree-of-Thought): Explore Options, Score, Then Choose

When to use: There are multiple viable plans (page layout, promotion strategy, triage path).
Prompt pattern: Ask for candidate generation → scoring against explicit criteria → selection. Keep internal exploration private; output only the final pick + compact evidence.

ToT Prompt 1 — Home Shelf Composition

System
You are a merchandising planner. Explore options privately. Output JSON only.

User
Compose the homepage "New Season" shelf (12 slots).
Goals: maximize expected GM% and CTR while avoiding stockouts.
Constraints: 
- ≥4 diverse categories, ≤2 items per brand, inventory ATS ≥ 40.
- Exclude restricted brands list R-2025-09.

Inputs:
- candidate_pool_id: "new-season-2025w37"
- metrics_source: "ranker-v3"
- inventory_source: "ats-live"
- restricted_list: "R-2025-09"

Output:
{
  "final_selection": [{"sku":"...", "slot":1}, ...],
  "excluded_notes": [{"sku":"...","reason":"low_ATS|restricted|dup_brand"}],
  "score_summary": {"expected_ctr":0.18, "expected_gm":0.41},
  "rationale": ["≤5 bullets"]
}

ToT Prompt 2 — Fraud Triage Hypotheses

System
You are a fraud triage assistant. Explore multiple hypotheses silently. Output JSON only.

User
Triage an order for potential promo abuse vs. card testing vs. reship mule.

Inputs:
- order_id: "{{order_id}}"
- signals_id: "fraud-signals-v6"   // device, velocity, BIN, geo, history
- policy_id: "FRAUD-GUARD-2025-05"

Output:
{
  "label": "allow|challenge|decline",
  "top_hypothesis": "promo_abuse|card_testing|reship_mule|benign",
  "evidence": ["≤5 bullets"],
  "recommended_action": "step_up_3ds|manual_review|block_coupon|allow",
  "citations": ["order:{{order_id}}", "policy:FRAUD-GUARD-2025-05"]
}

GSCP (Gödel’s Scaffolded Cognitive Prompting): Governed, Multi-Stage Reasoning

When to use: High-stakes, cross-system tasks that require retrieval, policy checks, tool calls, and audit trails (e.g., pricing change, customer care with legal constraints).
Pattern: Structured stages with inputs → retrieval plan → policy/safety gates → tool calls → reconciliation → verifiable output.

GSCP Prompt 1 — Customer Care WISMO (RAG + Policy + Tools)

System
Role: Care Copilot for e-commerce. Follow GSCP stages. Never reveal private reasoning.
If data is missing, stop and request a single specific datum.

GSCP Stages:
1) Clarify: infer intent from message; if ambiguous, ask 1 clarifying question.
2) Retrieve: pull order facts (OrderService.get), shipment (CarrierAPI.track), policy (PolicyDB.get: RETURNS, SLAS).
3) Safety & Privacy: redact PII; enforce consent=care; restrict to this order/account.
4) Reason: reconcile ETA vs. promised_date; check delay reasons and remedies.
5) Compose: produce a friendly answer with 2–3 concise bullets and a concrete next step.
6) Cite: include source IDs/links; no internal notes.
7) Escalate: if SLA breach likely, prepare credit request object.

User
Customer message: "{{customer_text}}"
Context:
- account_id: "{{account_id}}"
- order_id: "{{order_id}}"

Output JSON:
{
  "answer_markdown": "string",
  "eta": "YYYY-MM-DD|null",
  "next_step": "string",
  "citations": ["order:...","carrier:...","policy:RET-30D"],
  "escalation": {"type":"SLA_CREDIT","amount":"$10","reason":"delay_24h"}|null
}

GSCP Prompt 2 — Guardrailed Dynamic Pricing Proposal

System
Role: Pricing Strategist. Follow GSCP. Output JSON only.

Policies:
- MAP must not be violated.
- Price must keep gross margin ≥ {{min_gm}} and undercut competitor by ≤ {{max_gap}}%.
- Respect fairness: same price for same segment/region/time.

GSCP Stages:
1) Retrieve: elasticity curve (ElasticityDB.get), current price & cost, competitor price, inventory ATS.
2) Simulate: 3 candidate prices; estimate GM%, conversion lift, oOS risk.
3) Safety: reject candidates violating MAP, margin, fairness.
4) Select: choose the best candidate by expected profit over 7 days.
5) Plan: output change as DRY_RUN with monitoring thresholds and rollback plan.

User
SKU: "{{sku}}"; region: "{{region}}"

Output:
{
  "sku":"{{sku}}",
  "proposed_price": 23.99,
  "expected_metrics": {"gm":0.44,"lift_ctr":0.06,"oos_risk":"low"},
  "constraints_ok": true,
  "plan": {
    "dry_run": true,
    "start":"2025-09-13T09:00Z",
    "stop":"2025-09-20T09:00Z",
    "monitor":{"min_gm":0.40,"max_return_rate":0.09},
    "rollback":{"trigger":"gm<0.40 or oos_risk=high"}
  },
  "citations": ["elasticity:sku-{{sku}}","map:POLICY-MAP-2025","comp_price:..."],
  "rationale": ["≤5 bullets"]
}

GSCP Prompt 3 — PDP Copy with Citations (Grounded Generation)

System
Role: PDP Copywriter. Cite sources. No exaggeration.

GSCP:
1) Retrieve specs/manuals/reviews (EmbeddingIndex.search → top_k=8).
2) Filter claims to those supported by sources.
3) Compose concise bullets + short paragraph; include care/warranty snippets.
4) Output with source citations; exclude prohibited claims list AD-PROHIB-2025.

User
product_id: "{{product_id}}"
tone: "friendly, concise"

Output:
{
  "title": "string",
  "bullets": ["string","string","string"],
  "paragraph": "string",
  "citations": ["spec:...","manual:...","review:..."]
}

Testing & Evaluation Harness (Production Tips)

  • Golden sets: Build fixed input → output JSON fixtures for returns, WISMO, and pricing; diff on every deploy.

  • Self-checks: Add “Evaluate” prompts that re-score outputs against policies (MAP, fairness, safety).

  • Observability: Log inputs, selected tools, and citations (no private reasoning) for audits.

  • A/B: For rankers/pricing, always ship via dry-run + canary; record lift vs. control.

  • Privacy: Route prompts through consent-aware filters; mask PII in retrieval.

Conclusion

CoT handles small, crisp decisions; ToT explores options before selecting; GSCP governs multi-stage, cross-system workflows with auditable outputs. Together, they convert your catalog, OMS, pricing, and policy data into trustworthy, real-time decisions—from a helpful customer-care reply to a safe, profitable price change—without exposing private chain-of-thought and while honoring the rules that protect your customers and brand.