Generate a data mapping with AI

Ask about this Page
Copy for AI
View as Markdown

Use an LLM to draft the JSONata expressions for your data mapping, then check each expression before you add it to AI Hub.

A data mapping can contain dozens of expressions, one for each field the provider expects. An LLM can draft most of them if you give it the right inputs. It can also invent bindings, attribute names, or fields that don't exist, so always check the result.

This page describes the inputs to collect, a prompt you can adapt, and how to check the output. For the feed entry structure and the available bindings, see JSONata data mapping.

Collect the inputs

The AI produces better expressions when it knows your data and the target schema. Collect the following:

  • A sample feed entry: one product variant in the feed entry structure, with productData, variant, store, and shippingMethods. To build one, see Test your JSONata mapping locally.
  • Your Product Type definition: the names and types of the Attributes your variants use, so the AI doesn't guess attribute names.
  • The target fields: the field names and requirements from the data mapping page of your provider, such as OpenAI product data, Google product data, or Stripe product data.
  • The available bindings: the variable and function bindings from the Bindings section of your channel's Product sync tab. For the defaults, see JSONata data mapping.

Remove personal data and confidential values from the sample before you share it with an LLM.

Write the prompt

Paste your inputs into a prompt like the following. Replace each placeholder in angle brackets.

Example prompttext
You write JSONata expressions for a commercetools AI Hub data mapping.

Each expression runs against one product variant entry with these top-level
fields: productData, variant, store, shippingMethods. Here is a sample entry:

<paste the feed entry JSON>

These are the only bindings available (variables $country, $locale, $storeKey;
functions $tail, $getAttribute, $storeBaseUrl, $priceToAmount, $formatPrice).
$priceToAmount takes a price value object, and $formatPrice takes the amount and
the same price value object. Paste the bindings from your channel if they differ:
<paste the variable and function names and bodies>
Do not use any other custom functions or bindings.

The variant Attributes are defined by this Product Type:

<paste the Product Type name, Attribute names, and types>

Write one JSONata expression for each of these target fields:

<paste the target field names, their meaning, and whether each is required>

Rules:
- Use only fields that exist in the sample entry or the Product Type.
- Read localized values with $lookup(productData.name, $locale).
- Return a string, number, or boolean as the target field expects.
- Guard price and sale-price expressions. For price, use
  variant.price ? $priceToAmount(variant.price.value) ~> $formatPrice(variant.price.value) : ""
  and for sale price, use
  variant.price.discounted ? $priceToAmount(variant.price.discounted.value) ~> $formatPrice(variant.price.discounted.value) : ""
  Do not substitute zero when the value is missing.
- If a field can't be mapped from the available data, write "NOT MAPPABLE"
  and explain why instead of guessing.
- A variant without availability is "out_of_stock". A category ID alone
  does not provide a provider taxonomy path; mark that field "NOT MAPPABLE"
  unless the required taxonomy value or a maintained mapping is supplied.
- Return the result as a list: target field, expression, one-line explanation.
If the first answer is incomplete, ask the AI to fix specific fields. A short follow-up such as "The size Attribute is a number. Convert it to a string." works better than repeating the whole prompt.

Check the result

Treat every generated expression as a draft:

  1. Run each expression against your sample entry with the local test and compare the output with the value you expect.
  2. Check that every attribute name matches a name in your Product Type, including its casing.
  3. Check that the expression only calls bindings that exist in your channel.
  4. Test the expressions with variants that have missing attributes, a null price, or missing availability. For an example, see Check for missing values.
  5. Compare the value types with the requirements on the provider's data mapping page, for example whether a price is a number or a formatted string.
  6. Export the product data in AI Hub. An expression that returns no value gives an empty cell. An expression that can't be evaluated fails the export and names the function and SKU.

Collect the inputs with the Commerce MCP

If your LLM client supports MCP, it can read your real product data and build the sample feed entry for you. Use a Managed Commerce MCP Server, which you configure in the Merchant Center. This step is optional. The generic prompt above works with a feed entry that you paste in.

Enable the read tools

Enable only the tools the LLM needs, and no tools that create or update data. For a data mapping, these four read tools are enough:

  • read_product_projections: reads the Product Projections and Product Variants to map.
  • read_product_types: reads the Attribute definitions of your Product Types.
  • read_stores: reads the Store that your Agentic Channel uses.
  • read_shipping_methods: reads the Shipping Methods for the shippingMethods field.
For all available tools, see Commerce MCP.

Scope the product data

By default, read_product_projections returns the published Product Projection without a scoped price. To get the same price shape as in the feed entry, pass these parameters:
  • storeProjection: the key of the Store that your Agentic Channel uses. It filters prices and inventory to the Store's channels and applies the Store's locales.
  • priceCurrency: a currency code such as EUR. This parameter enables price selection.
  • priceCountry, priceCustomerGroup, and priceChannel: optional price selection inputs. They only apply together with priceCurrency.
With these parameters, each variant in the response includes the scoped price field that your expressions read as variant.price.
To avoid depending on the LLM to set these values, pin them in the server configuration. A tool customization can fix a parameter to a constant value or set a default. For details, see Managed MCP Servers.

Assemble the feed entry

The MCP returns API resources, not a feed entry. Ask the LLM to combine them in the feed entry structure. For example:

Example prompt for the MCPtext
Use the Commerce MCP tools to build one feed entry for the variant with
SKU <SKU>. Follow these steps:

1. Call read_product_projections with a where predicate for the SKU,
   storeProjection "<store key>", priceCurrency "<currency>",
   priceCountry "<country>", and priceChannel "<distribution Channel ID>".
2. Set productData to the Product Projection.
3. Set variant to the Product Variant whose sku matches, including its
   scoped price.
4. Call read_stores for the Store with key "<store key>" and set store to
   the result.
5. Call read_shipping_methods and set shippingMethods to the results.

Return only the JSON object with the four top-level fields.
Save the result as feed-entry.json and use it in the local test. Compare it with the structure in JSONata data mapping before you generate expressions from it.

Check for hidden fields

An MCP Server can redact or drop fields from tool responses. If the server uses response filtering, fields that the LLM never sees can't appear in its expressions, and the sample feed entry can miss fields that exist in your data. Check the response filtering settings of the server if an expected field is missing.

Next steps