Check AI-written meta descriptions for length and duplicates
Get meta descriptions for 10 pages from an AI, check length, duplicates, shared first 30 characters and keyword with a script, then re-prompt only the failures.
AI-written descriptions read smoothly, so every one looks fine by eye. Count length and duplicates with a script, and rewrite only the pages that fail. For the brief to prepare before this step, see Create an SEO content brief with AI. The pages and prompts below are Korean, as they were run; the script works on any language.
[1] Decide where the check criteria come from. Google's snippet documentation says (page last updated 2026-04-20):
There is no character limit, and the snippet is cut to the device width. The same page says snippets are mostly built from the page content, may differ per search, and that the meta description may be used when it describes the page better than the content does. Nothing guarantees your description is shown as written. So the 70–120 characters used below is a team rule, not a Google rule. Set a separate range for English pages, such as 120–160.
[2] Put the page list in a tab-separated file: id, title, keyword. Every title and company is made up. Pages p01–p03 are deliberately similar pages of one site.
p01 달빛농원 감귤 선물세트 구성과 가격 감귤 선물세트p02 달빛농원 한라봉 선물세트 구성과 가격 한라봉 선물세트p03 달빛농원 천혜향 선물세트 구성과 가격 천혜향 선물세트p04 산책로 지도 앱 오프라인 지도 내려받기 오프라인 지도p05 산책로 지도 앱 기록 내보내기(GPX) GPX 내보내기p06 해온 서점 회원 등급과 적립금 안내 적립금p07 해온 서점 배송 조회와 반품 방법 반품p08 소리나루 이어폰 블루투스 페어링 문제 해결 블루투스 페어링p09 소리나루 이어폰 펌웨어 업데이트 방법 펌웨어 업데이트p10 푸른길 요가원 첫 수업 준비물과 예약 요가 첫 수업[3] Build the prompt. Fix the output to one JSON object per line so a script can read it. The length rule is left out on purpose, to see what length the AI picks when it isn't told.
아래는 웹사이트 페이지 10개의 목록입니다. 열은 탭으로 구분되며 id, 제목, 핵심어 순입니다.각 페이지의 meta description 을 한국어로 써 주세요. 규칙:- 페이지마다 한두 문장. 검색 결과에서 그 페이지를 고르게 만드는 설명.- 핵심어를 자연스럽게 넣을 것.- 출력은 한 줄에 JSON 객체 하나(JSON Lines): {"id": "...", "description": "..."}- 다른 텍스트, 코드 펜스 금지. [4] Append the list and run. claude -p answers once and exits; --max-turns 1 allows a single turn.
$ cat head.txt pages.tsv > prompt.1.txt$ claude -p --model sonnet --max-turns 1 < prompt.1.txt > out.1.jsonl$ head -2 out.1.jsonl{"id": "p01", "description": "달빛농원 감귤 선물세트의 구성과 가격을 한눈에 비교해 보세요. 명절과 감사 인사에 어울리는 감귤 선물세트를 고르는 데 도움이 됩니다."}{"id": "p02", "description": "달빛농원 한라봉 선물세트의 구성과 가격을 확인하세요. 크고 향긋한 한라봉으로 마음을 전할 선물세트를 합리적으로 고를 수 있습니다."}[5] Write the check script. For each description it checks length (after collapsing whitespace, len()), exact duplicate, same first 30 characters, and keyword presence.
#!/usr/bin/env python3"""usage: check_meta.py pages.tsv out.jsonl MIN MAX — length, exact duplicate, same first 30 chars, keyword"""import sys, json, collectionspages = {}for line in open(sys.argv[1], encoding="utf-8"): pid, title, kw = line.rstrip("\n").split("\t") pages[pid] = kwlo, hi = int(sys.argv[3]), int(sys.argv[4])desc = {}for line in open(sys.argv[2], encoding="utf-8"): if line.strip(): row = json.loads(line) desc[row["id"]] = " ".join(row["description"].split())head = collections.defaultdict(list)full = collections.defaultdict(list)for pid, d in desc.items(): head[d[:30]].append(pid) full[d].append(pid)bad = 0for pid in pages: d = desc.get(pid) if d is None: print(f"{pid} MISSING"); bad += 1; continue errs = [] if not lo <= len(d) <= hi: errs.append(f"length {len(d)}") if len(full[d]) > 1: errs.append("duplicate of " + ",".join(p for p in full[d] if p != pid)) elif len(head[d[:30]]) > 1: errs.append("same first 30 chars as " + ",".join(p for p in head[d[:30]] if p != pid)) if pages[pid] not in d: errs.append(f"missing keyword '{pages[pid]}'") print(f"{pid} {'FAIL ' + '; '.join(errs) if errs else 'ok'}") bad += bool(errs)print(f"{len(pages)} pages, {bad} failed")sys.exit(1 if bad else 0)[6] Check against the team rule, 70–120.
$ python3 -I check_meta.py pages.tsv out.1.jsonl 70 120 | grep -v ' ok$'; echo "exit ${PIPESTATUS[0]}"p03 FAIL length 62p09 FAIL length 6110 pages, 2 failedexit 1p03 and p09 are too short. The other 8 were 70–80 characters, just above the floor. This run produced no duplicates and no missing keywords.
[7] Re-prompt only the failures. Rerunning everything would change the 8 that passed, so send just the failed ids and the check results.
$ python3 -I check_meta.py pages.tsv out.1.jsonl 70 120 | grep FAIL > fails.txt$ grep -E '^(p03|p09)' pages.tsv > redo.tsv$ cat prompt.2.txt아래 페이지의 meta description 이 길이 규칙(70~120자)에 맞지 않습니다. 목록의 id 만 다시 써 주세요.- 70자 이상 120자 이하(공백 포함), 한두 문장.- 핵심어(셋째 열)를 그대로 넣을 것.- 이전 설명과 다른 문장일 것.- 출력은 한 줄에 JSON 객체 하나: {"id": "...", "description": "..."} 다른 텍스트 금지. 페이지(id, 제목, 핵심어):p03 달빛농원 천혜향 선물세트 구성과 가격 천혜향 선물세트p09 소리나루 이어폰 펌웨어 업데이트 방법 펌웨어 업데이트 이전 설명과 검사 결과:p03 FAIL length 62p09 FAIL length 61$ claude -p --model sonnet --max-turns 1 < prompt.2.txt > out.2.jsonl$ cat out.2.jsonl{"id": "p03", "description": "달빛농원 천혜향 선물세트의 구성과 가격을 한눈에 정리했습니다. 용량별 구성품과 배송 안내, 포장 상태까지 꼼꼼히 확인해 보세요."}{"id": "p09", "description": "소리나루 이어폰 펌웨어 업데이트 방법을 단계별로 정리했습니다. 연결 상태 점검부터 완료 확인까지 처음이라도 차근차근 따라 해 보세요."}[8] Merge the two results by id and check again. The new descriptions are 71 and 74 characters, barely over the floor.
$ python3 -I check_meta.py pages.tsv merged.jsonl 70 120 | grep -v ' ok$'; echo "exit ${PIPESTATUS[0]}"10 pages, 0 failedexit 0[9] The duplicate and keyword checks never fired on model output, so test them on bad.jsonl, a hand-edited copy of merged.jsonl: p02 now starts with the same 30 characters as p01, p05 lost its keyword, and p07 got p06's sentence (these errors are not the model's).
$ python3 -I check_meta.py pages.tsv bad.jsonl 70 120 | grep -v ' ok$'; echo "exit ${PIPESTATUS[0]}"p01 FAIL same first 30 chars as p02p02 FAIL same first 30 chars as p01; missing keyword '한라봉 선물세트'p05 FAIL missing keyword 'GPX 내보내기'p06 FAIL duplicate of p07p07 FAIL duplicate of p06; missing keyword '반품'10 pages, 5 failedexit 1Passing does not make a description good. Whether it matches the page, and whether it invents contents or prices, takes a human reader.