Shopify Functions: Metafield JSON Returning Null (Size Limit?)

Hi everyone,
I’m using Shopify Functions with the Cart Transform API.

Inside run.graphql, I’m accessing a shop metafield of type JSON.

Today I noticed that, under certain conditions—possibly due to the size of the JSON—the metafield is returned as null in my function input.

The JSON value I’m storing has around 10,000 characters, which is well below the 2 million character limit. However, when the value is returned as null, I don’t see any error or warning in the logs indicating an issue.

Interestingly, when I reduce the size of the JSON, it starts showing up again in the input. This leads me to believe there’s some kind of undocumented limit in play.

Does anyone know if there’s a documented size limit for metafield values used within Shopify Functions, specifically in the run.graphql context? Any insights would be appreciated.

Thanks!

Yes, there is a limit of 10000 bytes which is listed here: About Function input and output

Metafields with values exceeding 10,000 bytes in size will not be returned.

Hi Anton,
Thanks for sharing.

I’m trying to understand why, even when a limitation is hit, Shopify Functions continue running without triggering any message or warning to developers or partners. That’s a bit crazy. There’s no way we can reliably measure the byte size of a metafield before using it in a Function.

If a customer doesn’t report the issue, we might never notice it. At least, I don’t see a viable way to accommodate such checks. Do you have any suggestions?

Thanks again.

We’re checking the size of the data before writing it to the metafield and making sure it never exceeds 10000 bytes.

There’s no way we can reliably measure the byte size of a metafield before using it in a Function.

Are you able to control the data that’s being stored in the metafield?

1 Like

Hi Anton,
Yes, that is a good idea!

I can use FLOW to run a JS checker (not 100% accurate) and throw something in case it exceeds 10kb.

Anyway, i think SHOPIFY should be more serious on this, i cannot understand why they simply return null and do not throw any error in this case. this is critical.

I don’t think throwing an exception is necessarily the right approach either - it’s possible that you allow a brand/merchant to configure which namespace/key pair to target a metafield that’s not in your control. It’s also possible that the metafield is a non-critical part of function input.

I would suggest treating ‘None’ (or null), as meaning ‘does not exist, or is over 10kb in size’ - either way, it’s invalid.

This could be a nice reason to have something like a ‘warning’ level, rather than an ‘error’ level, from an observability standpoint. Perhaps something that’s visible to the developer, but not the brand/merchant.

Hi @bkspace ! Yes, anything that can bring something to devs/partners attention if happening - the worse scenarium is exacly what we currently have, nothing is observably in this matter.

Do you guys know if this limit is a sum of all metafields or for each one?

What i need to solve is: i have a list of 40k zip codes and I need to pull them in my Delivery Customization Function API