CustomGPT.ai Blog

How do I make my chatbot recognize product codes?

You make a chatbot recognize product codes by: defining the exact code formats, detecting codes with regex or entities, validating them against your product catalog or API, and—if you use CustomGPT.ai—feeding it your catalog and passing the detected code into each conversation.

Scope:
Last updated – November 2025. Applies globally; ensure product-code chatbots follow privacy laws like GDPR and CCPA/CPRA when codes are linked to identifiable customers, and apply OWASP-style input validation.

Plan your product code formats

Before touching your chatbot, get crystal clear on what a “product code” actually is in your business.

  1. List every identifier customers might send (SKU, UPC/EAN, internal item ID, variant ID, etc.).
  2. For each identifier, define: length, allowed characters, separators (dashes, slashes), prefixes, and case rules.
  3. Note any checksum logic or patterns (for example, starting with AB- for accessories).
  4. Decide which codes the bot should support first (usually one or two primary ID types).
  5. Collect a sample set of real codes (valid and invalid) to use later in testing.

This definition step makes your regex, entity configuration, and validation rules much simpler and more reliable.

Detect product codes with regex or pattern rules

Regex (regular expressions) is usually the fastest way to spot code-shaped text inside a chat message.

  1. For each code type, write an allow-list regex (e.g., ^[A-Z]{3}-\d{4}$ for ABC-1234).
  2. Avoid overly permissive patterns like .*\d+.* that matches almost everything. OWASP recommends allow-listing expected characters and formats rather than block-listing bad ones. 
  3. Run your patterns over historical chat logs or sample messages to see where they misfire.
  4. Add unit tests that cover edge cases: lowercase, missing separators, extra spaces, screenshots pasted as text, etc.
  5. Implement the regex check as a pre-processor in your bot or middleware so you can tag the message with product_code=<value> before calling your NLU or backend.
  6. Log both matched and unmatched values so you can refine patterns over time.

Use regex when formats are strict and stable; combine it with entities when you also need contextual understanding.

Use entities or NER in your chatbot platform

Most modern NLU platforms extract structured data using “entities.” Product codes are a great fit.

  1. In your NLU (Rasa, Dialogflow CX, Azure CLU, etc.), create a custom entity for product codes or IDs. 
  2. If your platform supports regexp entities (like Dialogflow CX), encode your product code regex directly on the entity type. 
  3. Where list entities are available, populate them with your top products or frequently used codes; this improves recall for known codes and helps with partial matches. 
  4. Add labelled training examples where the product code is annotated as that entity in realistic user utterances.
  5. If your platform supports multiple components per entity (for example, list + learned), configure both: the model learns context while the list/regex enforces structure. 
  6. Combine your NLU-extracted entity with your regex pre-checks—if both agree, the code is very likely validly formatted.

Entities make your code recognition robust when users mix codes with natural language (“Can you check SKU 123-456?”).

Combine entities with lookup lists or tables

Lookup tables or list entities are perfect when:

  • Your code space is large but bounded (for example, 20k SKUs), and
  • You want higher recall for real, known codes.

To use them effectively:

  1. Export a list of product codes (and optional synonyms) from your catalog.
  2. Load that list into your NLU as a lookup table or list entity.
  3. Refresh the list periodically (nightly or weekly) alongside catalog updates.
  4. Use the lookup match as a strong signal, but still validate against the live catalog to catch discontinued or restricted items.

Validate product codes against your catalog or API

Detecting a code is only half the job; you also need to confirm it’s real and usable.

  1. Choose a single source of truth (product database, PIM, e-commerce platform API).
  2. Create a lightweight “lookup” endpoint that accepts a code and returns normalized product data or a clear error (not found, inactive, etc.).
  3. When your bot or NLU flags a product_code, call this endpoint synchronously in the conversation.
  4. Apply both syntactic validation (matches your regex/entity) and semantic validation (exists in catalog, allowed for the customer’s region). 
  5. If the code is invalid, respond with a helpful clarification (“That code isn’t in our catalog. Can you check the label or send a photo?”).
  6. If valid, enrich the conversation with product name, image, key attributes, and next actions (add to cart, check stock, etc.).

This API validation layer keeps your chatbot responses accurate as your catalog changes.

How to do it with CustomGPT.ai

If your chatbot is powered by CustomGPT.ai, you’ll usually combine CustomGPT.ai for knowledge with your own UI logic for pattern detection.

Load your product catalog into CustomGPT.ai

  1. Create or open an AI agent in the CustomGPT.ai dashboard
  2. Go to Manage AI agent data and add sources containing product information: product pages, support articles, spec sheets, or catalog docs. 
  3. Upload PDFs or documents (for example, catalog exports, price lists, manuals) using the Add PDFs and documents flow. 
  4. If your catalog is on the web, create an agent from your website or sitemap so CustomGPT.ai crawls all relevant product pages. 
  5. Wait for indexing to complete; your agent can now answer questions using this product data.

Deploy a chat interface backed by CustomGPT.ai

  1. Decide where customers will talk to the bot: website widget, app chat, help center, or social.
  2. Use a CustomGPT.ai chat widget or your own frontend that calls the CustomGPT.ai API
  3. In your frontend code, add regex or input parsing to detect potential product codes in each user message (following the earlier regex section).
  4. When you detect a code, include it in the message you send to CustomGPT.ai—either in the user text (“User provided product code: ABC-1234”) or as structured context alongside the user’s question.
  5. Optionally, call your own product API first and send the normalized product data as context so the agent can answer with richer, catalog-accurate details.

Tune the agent for product-code questions

  1. In the agent’s instructions, tell it explicitly how to treat product codes (for example, “When a code like ABC-1234 is provided, use the product catalog sources to answer.”).
  2. Add example Q&As to your content where the user mentions codes and the answer includes product information.
  3. Monitor chat logs and export agent data from CustomGPT.ai to see where code-related queries succeed or fail, then adjust your regex, prompts, or catalog sources. 

This pattern keeps code detection logic in your app while CustomGPT.ai handles the heavy lifting of understanding and answering from your product content.

Example — chatbot identifying a product code in a message

Imagine a support chat on your store:

  1. The user types: “Hi, can you check availability for SKU ABC-1234 in medium?”
  2. Your frontend applies a regex and extracts ABC-1234 as a candidate product code.
  3. Your backend calls the product catalog API with that code and gets back product metadata plus stock information.
  4. In parallel (or after), you send a message to your CustomGPT.ai agent that includes the user’s text plus structured context: “Product code: ABC-1234 (T-Shirt X), stock: in warehouse A.”
  5. CustomGPT.ai uses your product content to answer: summarizing the product, confirming availability, and suggesting next steps (add to cart, shipping estimates).
  6. If the code fails validation, your bot replies with guidance and maybe a link to browse categories instead.

Conclusion

Accurate support relies on more than just spotting a serial number; it requires understanding the technical specifications and availability behind it. By feeding your manuals and parts lists into CustomGPT.ai, you ensure that every validated SKU triggers a knowledgeable, detailed explanation rooted in your actual documentation rather than a generic fallback. Connect your catalog sources now to give your AI the context it needs to resolve complex product inquiries instantly.

FAQs

How can I make my chatbot recognize product codes reliably?

To make your chatbot recognize product codes reliably, first define each code format in detail, including length, allowed characters, and prefixes. Then use allow-list style regex or entities to detect code-shaped text, validate matches against a live product catalog or API, and return helpful responses when a code is invalid or confirmed.

How do I use CustomGPT.ai to handle product code questions in chats?

With CustomGPT.ai, you load your product catalog as data sources, then deploy a chat interface that detects product codes in the frontend using regex or entities. When a code is found, you can call your catalog API, pass the validated code and product data into each CustomGPT.ai request, and instruct the agent to use that context to answer detailed, code-specific questions.

3x productivity.
Cut costs in half.

Launch a custom AI agent in minutes.

Instantly access all your data.
Automate customer service.
Streamline employee training.
Accelerate research.
Gain customer insights.

Try 100% free. Cancel anytime.