How to generate Shopify product descriptions with GPT (OpenAI API) and Python

This blog post explains how to use the OpenAI API and Python to generate Shopify product descriptions automatically. It walks you through the steps required to set up the process, including setting up the OpenAI API, creating a Python script and generating potentially hundreds of high quality descriptions for your store.

Way signs with the word "Content" pointing from Shopify Logo to OpenAI Logo

Integrating large language models for your eCommerce store doesn't need to be complicated

1. What's GPT and why use davinci003 instead of ChatGPT?

2. Step-by-step guide to integrating Shopify API and OpenAI API

3. Setting up the data workflow

4. Best practices for prompting product descriptions

5. Prompt templates for product descriptions

6. Conclusion: It's all about prompting

Are you tired of manually writing product descriptions for your Shopify store? Have you considered automating the process but aren't sure where to start? In this blog post, we'll show you how to create your own Shopify to GPT automation for generating product descriptions with the power of natural language generation (NLG).

Not using Shopify? No problem! This process can be applied to any other shop system you might be using. We'll cover the basics of setting up the automation and how to write effective prompts for GPT to generate accurate descriptions.

Understanding which kinds of prompts work well for certain kinds of products or text formats is important for achieving quality results. We'll walk you through best practices for prompt writing, so you can create your own prompts that work well for your specific product offerings.

Finally, we'll provide you with ready-to-use Python code for pulling data from Shopify, prompting GPT, and sending the generated text back to your Shopify store. By the end of this blog post, you'll have the knowledge and tools to automate the process of writing product descriptions, saving you time and effort in the long run.

1. What's GPT and why use davinci003 instead of ChatGPT?

Davinci003 and ChatGPT are both large language models developed by OpenAI that can be used for a variety of natural language processing tasks. While they share many similarities, there are also some differences that could make one more suitable than the other depending on the specific use case. Here are a few pros and cons to consider when comparing davinci003 and ChatGPT: Watch our webinar recording

Among a variety of reasons, including cost and ease of integration, we had ultimately decided to use davinci003 (GPT-3) as our model of choice.

The video covers following reasons:

  • Davinci is better at executing tasks - especially simple ones.
  • There is no ChatGPT API that could have been integrated - davinci is available through OpenAIs API.

Other sources to be considered:

  • Neuroflash discusses whether ChatGPT or davinci is better in their blog post.
  • OpenAIs publication covers more pros and cons around the usage of davinci, respectively InstructGPT.
  • OpenAI also states: "The model (ChatGPT) is often excessively verbose and overuses certain phrases." (source)

If you're curious to see the live product description generation, feel free to keep watching the video. In the next chapters we are going to cover some implementation details that you're going to need if you want to set this up for yourself.

A documentation of OpenAI's list of models can be found here: OpenAI API Models

Nowadays, there is also the option to use Python Frameworks, such as LangChain or GenossGPT to flexibly exchange models endpoints without having to rely on OpenAI.

Furthermore, Shopify has announced and released their own in-platform function to create AI-generated product descriptions which they had announced in their Winter '23 Edition - check it out.

The issue with their in-platform feature? It doesn't really scale since you can only manually apply their generative AI for one product at the time.

2. Step-by-Step Guide to Integrating Shopify API and OpenAI API for Generating Product Descriptions

First of all, we need to set up a few prerequisites in order to integrate with Shopify's API.

We suggest to follow along Shopify's guide on setting up a custom app in your Shopify store.

Once that is done, go to your app settings and allow following Admin API access scopes:

  • read_products, write_products, read_product_listings, write_product_listings
API scope settings found under<your-store>/settings/apps/development

Additionally, we need to generate an API key in the tab "API credentials" that we are later going to use for accessing Shopify API endpoints. Later, we are primarily going to use Shopify's Products API as well as their ProductsListing API to retrieve and update product information.

At the same time, we are also going to require an OpenAI API key in order to send prompts to their large language models. API keys can be generated and accessed under once you're logged in with your user account.

Alright, we have our API keys set up in order to establish a connection between our shop data and OpenAI. What's left is to come up with a few Python code snippets to create that connection. If you're using a different content management system the code will need some tweaking.

As for accessing our list of products we integrated Shopify's ProductListings API via DataCater's REST source connector. Since we want to avoid continuously re-generating texts or having to manually trigger the process, DataCater is the optimal choice. By capturing changes in the CMS we can identify the right timing to refresh our product descriptions based on updates of relevant data fields (Read more on change data capture).

The convenient part? DataCater pipelines also allow executing custom Python functions. The process goes as follows:

  1. We register a change in our product data via change data capture
  2. That specific product's information is being pulled by our DataCater pipeline
  3. We include that product's data into a prompt and send a request to OpenAI's davinci003 API endpoint (see first code snippet)
  4. The received text can be post-processed or simply inserted into the product's datafield 'body_html' (see second code snippet)

Here are the required code snippets:

Snippet 1 - Prompt davinci003

response =
	headers = {      
		"Authorization": "Bearer {YOUR-OPENAI-API-KEY}" 
	json = {      
		"model": "text-davinci-003",      
		"prompt": prompt,     
		"max_tokens": 1024,      
		"n": 1,      
		"temperature": 0.5
response_text = response["choices"][0]["text"]

Snippet 2 - Update 'body_html' of a Shopify product

	+ str(row["id"]) + ".json",
	headers = { "X-Shopify-Access-Token": "{YOUR-API-KEY}" },
	json = {      
		"product": {        
			"id": row["id"],        
			"body_html": response_text      

Unlike the second snippet, the first one can be used independant from your shop system. The only variable that needs to be provided by you is the content of 'prompt'.

3. Setting up the Data Workflow for Automated Product Description Generation

After we've set up our API endpoints and adjusted respective code snippets to our shop system or CMS, what's left is to instantiate said pipeline.

Data Workflow that utilizes product data and davinci003 to generate product descriptions

Using DataCater's Pipeline Designer, this is a no-code task that anyone with a little bit of technical background can achieve. Of course, the shown Python code in the previous chapter would also work on your local machine, if you're running them from a Python script.

4. Best Practices for Prompting ChatGPT for Generating Shopify Descriptions

Now, what's left is to build the right prompts that yield the best results when it comes to eCommerce product descriptions.

You might wonder how "best" is defined in this case.

There are many factors to good product descriptions, such as sentence length, story and structure, readability, highlighting customer benefits and much more. For fashion product descriptions we recommend reading our 10 Fashion Copywriting Tips blog post.

If you're looking to generate oontent for different products, such as home appliances, DIY articles, beauty products or other industries, don't worry. Each industry has their own requirements that can be fulfilled by building the right prompt.

We recommend jumping straight to our webinar's section where we discuss tips on prompt building and how to restrict certain outputs (timestamp 43:13 of the above linked YouTube video). Another helpful tool is AIPRM, a browser extension with helpful prompt templates.

A thumb of rule is: Prompts with high information density and clear directives yield better outputs. Thus, you should focus on:

  • Giving concise and clear instructions - don't leave too much room for interpretation. For example you could:
    i) Specify the tone
    ii) Limit the output to a certain range of characters or words - keep that range narrow enough
    iii) Define the type of text output - a paragraph, headline or maybe bullet points?
  • Including product parameters into your prompt and if possible - explain their benefit
  • Defining do's and don'ts - for instance avoiding certain language or words

Pay attention to these tips and your output quality will skyrocket.

5. Example Product Description Templates for Prompting ChatGPT

Did you think we would leave you hanging with just a few best practice tips? Of course, we are going to provide a few generally applicable templates that you can adjust towards your needs.

In case you don't have any product data - besides the product name or title, you could go for something like this:

"Could you please write me a product description for {title of product}?”

Or if you need the description for different channels, such as Amazon, you could add:

"The output should be three to five bullet points."

Now, let's assume you have some product data. Play around by adding those features to your prompts, e.g.:

“Please write me a product description for {product name} by {brand}. It should be written for customers in the luxury segment and highlight the product’s {feature_list} features.”

The good part is: Since we can build those prompts in Python or any other programming language, we can dynamically leave out or add parts to our prompts based on missing or available attributes. No product database is perfect and we need to work with what we've got.

It's also very common to have a less structured product database. Not everyone owns or maintains a PIM system with a single data field for each product feature. Sometimes they are a bit mixed up, especially when it comes to marketplace sales. For these cases, we might want to try something more complex:

“Can you please generate a product description for a {product name} by {brand} with {feature1}, {feature2}, {feature3} and {feature4}? The description should contain a {50} characters title, a {80-120} words introduction and two {100 words} each subsections. The first section dealing with {feature1} and {feature2}. The second section dealing with {feature3} and {feature4}. {...}”

Curious about the outputs and results? Have a look at our webinar recording together with DataCater and convince yourself.

We didn't really find any useful resources around building eCommerce product description prompts. Feel free to reach out to us if you need any assistance or if you want us to add more examples!

Conclusion: It's all about prompting

We hope that you enjoyed our webinar and/or blog post read.

In conclusion, automating the process of generating product descriptions can save significant time and effort for eCommerce businesses. This data workflow, which utilizes GPT language models, can be applied to any shop system or database.

However, the quality of output depends heavily on the quality of the input data and the effectiveness of the prompts used. Writing effective prompts tailored to specific product offerings and data structures is crucial for achieving high-quality output.

By following the guidelines presented in this blog post and paying close attention to input data quality, everyone can develop a reliable and effective data workflow for generating product descriptions that meets their specific needs.

We can also recommend using tools that help with AI prompting, such as AIPRM.

Stacy Yee content marketing specialist

Jan Kaiser

CEO | Founding Partner

Jan is one of the founders at Xanevo and he is responsible for the implementation of customer projects, which includes project management and leading the technical implementation by the developers.

We will make you a smarter marketer for free. Join our newsletter.

Thanks for joining our newsletter.
Oops! Something went wrong.