Key takeaways
- AI Shopify metafields work in two layers: the definition (namespace, key, type) and the value. AI is strongest at generating values at scale.
- Define the structure first. A metafield definition fixes the type, and Shopify validates every value against it.
- Generate values with AI, then validate types before you write.
rich_text_fieldandjsonhave strict formats that a plain string will fail.- Push values in batches. The
metafieldsSetmutation accepts up to 25 metafields per call. 1- Metafield writes hit live product data. Review AI output before it reaches customers.
AI Shopify metafields are metafield values a model like Claude drafts for you - specs, care instructions, ingredient lists, structured PDP data - then validates and writes to your store through the Admin API. This guide is the workflow for doing that at scale without corrupting live product data.
This is the automation layer. If you have not created a metafield definition yet, start with our manual walkthrough: how to add metafields to Shopify products. That guide covers the admin UI. This one covers generating and pushing values with AI.
Why you can trust us
Jacques has over 15 years of development experience and has worked with hundreds of Shopify stores. We built Fudge - an AI-native Shopify page builder and store editor with a 5.0 rating and a Built for Shopify badge. We work with product data every day.
The two layers: definition vs value
Every metafield has two parts, and AI plays a different role in each.
The definition sets the structure. It fixes the namespace, key, type, and owner resource. You create it once per field. This is a governance decision, not a bulk task.
The value is the content for one product. This is where AI earns its place: writing hundreds of care instructions or spec sheets is exactly the kind of repetitive work a model does well.
The order matters. Define the field first, then generate values against it. Shopify validates every value you write against the definition’s type, so the definition is your guardrail.
Step 1 - Define the field once
A metafield definition has four required pieces:
| Part | Example | Notes |
|---|---|---|
| Namespace | specs | Groups related fields. Merchant-owned fields use any non-reserved namespace. 2 |
| Key | wattage | Unique within the namespace. |
| Type | number_integer | Fixes the data format. Shopify validates against it. 3 |
| Owner type | PRODUCT | The resource the field attaches to (also PRODUCTVARIANT, COLLECTION, and others). 4 |
You can create the definition in the admin (Settings > Custom data > Products) or with the metafieldDefinitionCreate mutation. 4
Here is the GraphQL version:
mutation {
metafieldDefinitionCreate(definition: {
name: "Wattage"
namespace: "specs"
key: "wattage"
type: "number_integer"
ownerType: PRODUCT
}) {
createdDefinition { id name }
userErrors { field message }
}
}
Choose the type deliberately. The type decides which values pass validation later. A short label wants single_line_text_field. A care paragraph wants multi_line_text_field. A number wants number_integer or number_decimal. A list of certifications wants list.single_line_text_field. 3
Shopify allows up to 256 metafield definitions per resource type for a merchant, so there is room to model a real catalogue. 5
For the point-and-click version of this step, see how to add metafields to Shopify products.
Step 2 - Generate values with AI
Now the field exists and its type is fixed. This is where you bring in Claude.
The pattern is the same for every field: give the model the product context and the target type, and ask for values in that exact shape.
Product specs
For a lighting product with a specs.wattage field typed as number_integer, the prompt is narrow:
Read the product title and description below. Return the wattage as
a plain integer with no units, no text. If wattage is not stated,
return null. Product: "Aria Pendant Lamp, 12W LED, warm white"
A tight prompt returns 12, which passes number_integer validation. A loose prompt returns “12 watts”, which fails.
Care instructions
For an apparel care.instructions field typed as multi_line_text_field, you can ask for a short paragraph derived from the material composition. The model reads the fabric, you get consistent care copy across the catalogue.
Related: create a care guide page in Shopify once the data is in place.
Ingredients and structured PDP data
For food, supplements, or beauty, a custom.ingredients field typed as list.single_line_text_field holds each ingredient as a separate value. Ask the model to split a supplied ingredient string into a clean array.
Ground the model in real source data. Feed it the existing description, supplier sheet, or PDF. Do not let it invent specs. An invented wattage or ingredient is a compliance problem, not a copy problem.
Step 3 - Validate types before you write
This is the step people skip, and it is the one that breaks live data.
Shopify validates every value against the definition’s type on write. If the type does not match, the write fails - or worse, a malformed value slips through and renders as broken output on the page.
Match the value to the type before the API call, not after.
Two types need special care:
rich_text_field does not accept an HTML string or plain text. It accepts a specific JSON tree with a root node and children for paragraphs, lists, and text. 3 If you want rich text, ask the model for that JSON structure, not for HTML.
json accepts up to 128KB and must be valid JSON. Most other types cap at 64KB. 5
A quick validation pass before writing:
| Type | Accepts | Common AI mistake |
|---|---|---|
number_integer | Plain integer | Appending units (“12W”) |
list.single_line_text_field | JSON array of strings | Returning a comma-joined string |
rich_text_field | Shopify rich text JSON | Returning HTML or markdown |
boolean | true / false | Returning “yes” / “no” |
Run every batch through a schema check that matches the target type. Reject anything that does not fit rather than writing it and hoping.
Step 4 - Push values via the Admin API
Once values are generated and validated, write them with the metafieldsSet mutation.
The mutation takes an array. Each entry needs the ownerId, namespace, key, type, and value. 1
mutation SetSpecs($metafields: [MetafieldsSetInput!]!) {
metafieldsSet(metafields: $metafields) {
metafields { key value }
userErrors { field message }
}
}
Three limits shape how you batch:
- 25 metafields per call. Chunk your catalogue into groups of 25. 1
- 10MB request payload. Large
rich_text_fieldorjsonvalues fill this faster than short labels. 1 - Atomic per call. If one metafield in the array errors, none in that call persist. 1
The atomic behaviour is useful. A bad value in a batch of 25 stops the whole batch, so you catch the problem before any of it lands.
Use compare-and-set for concurrent writes. Since API version 2024-07, metafieldsSet supports a compareDigest input that only writes if the stored value still matches what you read. 1 This prevents an AI batch from overwriting a manual edit someone made in the admin.
Pushing via the Shopify AI Toolkit
If you run this through Claude Code, the Shopify AI Toolkit generates and validates the mutation against bundled schemas, then executes it through the Shopify CLI. It uses TOML for app-owned metafield definitions and knows the difference between app-owned and merchant-owned data.
For setup, see our Shopify AI Toolkit and Claude Code guide. One thing to know: toolkit store operations run on your live store immediately, with no draft step.
Governance: AI writes live data
This is the part that separates a safe workflow from a costly one.
Metafield writes are live. A value pushed by metafieldsSet is on the product the moment the call succeeds. There is no draft state for metafield values, and the Admin API has no undo.
Four rules keep this safe.
Review before write. Generate the full batch, read a sample, then write. Never pipe model output straight into the mutation with no human in the loop. Specs and ingredients carry legal weight.
Read current state first. Before overwriting an existing value, query what is there. Someone may have edited it by hand. Compare-and-set enforces this at the API level. 1
Write in small batches. Twenty-five per call is the ceiling, not a target for your first run. Start with one product, confirm it renders correctly, then scale.
Keep a record. Export the values you are about to overwrite before you write. The API keeps no rollback for you.
For merchant-facing data displayed to buyers, the safest surface is one with drafts and previews built in. That is the gap Fudge fills for teams that should not be running GraphQL against production.
Where AI fits, and where it does not
AI is strong at values. Generating specs, care copy, and ingredient lists across a large catalogue is repetitive and pattern-based. A model does it faster than a person and more consistently than copy-paste.
AI should not own definitions. The namespace, key, and type are structural decisions that affect your whole catalogue and your storefront rendering. Make those yourself, then let AI fill them.
AI needs validation. A model will confidently return “12 watts” for a number_integer field. The type system catches it only if you validate before writing.
Once values are in, you can surface them on the page and in structured data. See how to add structured data in Shopify to feed metafields into product schema, and customize a Shopify product page to display them.
For the wider view on building Shopify this way, read AI-first Shopify development.
Quick reference
| Step | Action | Tool |
|---|---|---|
| 1 | Define namespace, key, type, owner | metafieldDefinitionCreate or admin |
| 2 | Generate values from real source data | Claude with a type-specific prompt |
| 3 | Validate each value against its type | Schema check before write |
| 4 | Push in batches of 25 | metafieldsSet |
| 5 | Confirm on a product, then scale | Admin preview |
FAQ
It can generate the metafieldDefinitionCreate mutation for you, but the namespace, key, and type are structural choices that affect your whole catalogue. Decide those yourself and let AI fill the values. A wrong type at the definition level breaks every value written against it.
The metafieldsSet mutation accepts up to 25 metafields per call, with a 10MB total payload cap. The call is atomic, so if one metafield errors, none in that batch persist. Chunk a large catalogue into groups of 25.
The rich_text_field type does not accept HTML or plain text. It requires a specific JSON tree with a root node and children for paragraphs and lists. Ask the model to return that JSON structure directly, or use a multi_line_text_field if you do not need formatting.
Only with review. Metafield values are live the moment the write succeeds, and the Admin API has no undo. Generate the batch, read a sample, export the current values first, then write in small batches starting with a single product.
The manual workflow uses the admin UI to define and fill one field at a time, which is right for a handful of products. This AI workflow generates values at scale and pushes them through the Admin API. See our manual guide for the point-and-click version.
Yes. In Claude Code, the toolkit generates and validates the metafieldsSet mutation against bundled schemas and executes it through the Shopify CLI. It uses TOML for app-owned definitions. Note that its store operations run on your live store with no draft step.
Footnotes
-
Shopify, “metafieldsSet - GraphQL Admin API.” Documents the 25-metafields-per-call limit, 10MB payload cap, atomic behaviour, required inputs, and the
compareDigestcompare-and-set input added in version 2024-07. https://shopify.dev/docs/api/admin-graphql/latest/mutations/metafieldsSet ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 -
Shopify, “Manage metafield definitions.” Notes that merchant-owned metafields use any non-reserved namespace and that app-owned definitions use the reserved
$appnamespace. https://shopify.dev/docs/apps/build/metafields/definitions ↩ -
Shopify, “List of data types.” Lists metafield type identifiers including
single_line_text_field,multi_line_text_field,rich_text_field,number_integer,number_decimal,boolean,json, andlist.variants. https://shopify.dev/docs/apps/build/metafields/list-of-data-types ↩ ↩2 ↩3 -
Shopify, “metafieldDefinitionCreate - GraphQL Admin API.” Documents the mutation inputs (namespace, key, name, type, ownerType, access). https://shopify.dev/docs/api/admin-graphql/latest/mutations/metafieldDefinitionCreate ↩ ↩2
-
Shopify, “Metafield limits.” States 256 metafield definitions per resource type, the 64KB default value cap, and the 128KB cap for
jsonvalues. https://shopify.dev/docs/apps/build/metafields/metafield-limits ↩ ↩2