SEO
How Can You Use AI to Write Meta Descriptions That Match the Page Content?
Could an AI-written meta description make your page sound more useful than it really is? It can draft polished copy quickly, but the wording still needs to match what visitors will find on the page.
This guide walks through a single-page workflow using the OpenAI API and Python: provide the page title and visible text, ask for a concise description grounded in that evidence, then review the result before publishing. You’ll also check its character count and keep expectations realistic about how it may appear in search.
The key trade-off is straightforward: a dramatic promise may sound tempting, but an accurate summary sets a better expectation. I’d rather publish copy that reflects the page than invite a click with a claim the page cannot support.

Quick answer
For one page, the short version is: give the model the page title and visible text, request one concise description using only supported claims, and treat the result as a draft—not a fact-check. Review every promise against the page, then make sure the copy is readable, relevant, and specific to that URL.
If you’re following the Python route, the documented setup uses Python 3.10 or later, the OpenAI SDK, and an API key stored as OPENAI_API_KEY. The Responses API returns generated text through response.output_text; keep the key out of public or client-side code.
Count the draft’s characters if that helps you edit, but don’t treat a particular count as a display guarantee. Google does not prescribe a fixed character limit and may use page text or truncate the snippet to fit the device.
Step-by-step guide
What you need before drafting
Start with one page and have its title and visible on-page text ready. The model needs that page-specific evidence to draft a description grounded in what the page actually says, rather than relying on a URL alone.
You’ll also need Python 3.10 or later, an OpenAI API key, and a local environment where you can run a Python script. Keep the key private; you’ll use it when setting up the API connection in the next step.
I recommend copying the page text into a working note before you begin. That makes it easier to check the draft against the same content you gave the model.
Sources: Developer quickstart | OpenAI API; OpenAI Python API library | OpenAI API Reference.
Set up the Python environment and protect the API key
- Create an OpenAI API key and store it in your local environment as
OPENAI_API_KEY, rather than pasting it into your Python file. Keep it out of browser-side or mobile-app code, and don’t share scripts that expose the key.
For a POSIX-style shell, you can export the variable with export OPENAI_API_KEY="your-key"; use your shell’s equivalent environment-variable settings if you’re on another platform. Don’t commit a real key to a shared project.
- Install the official Python SDK from your local terminal:
pip install openaiThe SDK requires Python 3.10 or later. Once installed, you’re ready to make the API request in the next step; if the installation command fails, first confirm that your Python version meets that requirement.
Sources: Developer quickstart | OpenAI API; OpenAI Python API library | OpenAI API Reference; Best practices for API key safety | OpenAI Help Center.
Give the model page-specific evidence and clear constraints
Use the page title and visible on-page text as the request input. Label each clearly so the model can distinguish the page’s subject from the supporting details.
Add an instruction like this before the content:
Write one concise, readable meta description for this page. Use only claims supported by the supplied title and page text. Do not add benefits, results, offers, or specifics that the page does not state. Make the description relevant and distinct to this page, not generic copy. Return only the description.
Page title: [paste title]
Visible page text: [paste text]Keep the evidence specific to this URL; a URL alone does not give the model the page’s actual content. The prompt can reduce the chance of invented claims, but it can’t verify the draft for you, so check the returned wording against the page before publishing.
Sources: How to Write Meta Descriptions | Google Search Central; Developer quickstart | OpenAI API; OpenAI Python API library | OpenAI API Reference; Best practices for API key safety | OpenAI Help Center.
Generate and retrieve the draft
With the API key set and your page-specific prompt ready, put the request in a Python file. This example asks for one evidence-based draft and prints the model’s response for you to review.
from openai import OpenAI
client = OpenAI()
instructions = (
"Write one concise, readable meta description. Use only claims "
"supported by the supplied page title and text. Return only the description."
)
page_title = input("Paste the page title: ")
page_text = input("Paste the visible page text: ")
response = client.responses.create(
model="gpt-6-astra",
instructions=instructions,
input=f"Page title: {page_title}\nVisible page text: {page_text}",
)
print(response.output_text)Save the file and run it with python example.py, then paste in the title and visible text when prompted. The output is a draft, not a fact-check: compare its wording with the page before using it.
Sources: How to Write Meta Descriptions | Google Search Central; Developer quickstart | OpenAI API; OpenAI Python API library | OpenAI API Reference; Best practices for API key safety | OpenAI Help Center.
Review the draft against the page before publishing
Before publishing, open the page and check the draft against what a visitor can actually read there. Treat each promise, benefit, number, and named feature as a claim that needs clear support in the page text.
- Check the facts. If a phrase suggests a result, offer, or feature the page does not state, remove it or rewrite it to match the evidence. A prompt can guide the draft, but it does not replace this review.
- Check the fit. Make sure the wording describes this page’s main subject, reads naturally, and is specific enough that it would not work unchanged for a different URL. Google recommends descriptions that are relevant, unique, and descriptive.
- Check the promise. Ask whether the description sets an expectation the page fulfills. If it makes the page sound more comprehensive or useful than it is, choose the more accurate wording—even if it feels less dramatic.
Only publish the draft once its claims and tone match the page.
Sources: How to Write Meta Descriptions | Google Search Central; Developer quickstart | OpenAI API; OpenAI Python API library | OpenAI API Reference; Best practices for API key safety | OpenAI Help Center.
Check the draft and set expectations for search display
Use the returned draft as a candidate, then check its wording against the page before you publish it. Confirm that each specific claim is supported and that the description is clear, readable, and distinctive to this URL.
To get a simple character count in your script, store the output and print its length:
draft = response.output_text.strip()
print(draft)
print("Characters:", len(draft))Treat that number as an editorial check, not a display guarantee. Google does not prescribe a fixed character limit, and it may create a snippet from page text instead of using your meta description.
It may also truncate the snippet to fit the device, so prioritize an accurate, useful summary over hitting a particular count.
Sources: How to Write Meta Descriptions | Google Search Central; Developer quickstart | OpenAI API; OpenAI Python API library | OpenAI API Reference; Best practices for API key safety | OpenAI Help Center.
Handle unsupported copy or a different Google snippet
If the draft promises a result, feature, offer, or benefit you can’t find on the page, remove that wording or revise the prompt to say: “Use only claims directly supported by the supplied page text. If a detail isn’t stated, leave it out.”
Generate another draft, then check every claim against the page before publishing; the prompt helps set a boundary but does not verify the output for you.
If Google displays different wording, that doesn’t necessarily mean the meta description is broken. Google may create a snippet from page content when it considers that a better match for the query, and it may truncate the snippet to fit the device.
Check that the page itself clearly explains its subject, and treat the meta description as a candidate summary—not guaranteed search-result copy.
Sources: How to Write Meta Descriptions | Google Search Central; Developer quickstart | OpenAI API; OpenAI Python API library | OpenAI API Reference; Best practices for API key safety | OpenAI Help Center.
Next steps
Before publishing, check each factual claim, benefit, and promise against the page itself. If a phrase overstates what the page offers, trim it or rewrite it; a prompt can guide the draft, but it cannot replace your review.
Then make sure the description is clear and distinctive to that URL. A character count can help with editing, but it cannot guarantee what searchers will see because Google may choose wording from the page or shorten the snippet.
If the draft passes those checks, use it as the page’s meta description and take one practical next step: compare it with the visible page text once more before publishing. Aim for an honest summary that earns the right expectation, not a clickbait promise.