GrepBoard/Manuals
605 manuals ·

Filter AI-written search ad copy by character limits

·Tested on Claude Sonnet (sonnet alias) · Claude Code 2.1.302 · Python 3.12 · Ubuntu 24.04 · 2026-10 · limits per Google Ads Help·Test scope ↓·7 steps

Check responsive search ad headlines (30) and descriptions (90) with Python, counting CJK characters as 2, then send only failed or duplicate rows back to AI.

Ask an AI for ad copy and the sentences read well while the length rules go ignored. In Korean, Japanese and Chinese every character counts as 2, so counting by eye fails. Let a script count, and regenerate only the rows it flags. The same approach applied to meta descriptions is in Check AI-written meta descriptions for length and duplicates.

[1] Confirm the limits first. Google Ads Help, About responsive search ads, says:

FieldHelp text
Headlineup to 30 characters (3 minimum, 15 maximum)
Descriptionup to 90 characters each (2 minimum, 4 maximum)
Pathup to 15 each

For double-width languages:

A Korean headline therefore holds 15 characters and a description 45. The page does not say how spaces, digits, Latin letters or punctuation are counted. The script below counts Unicode East Asian Width W and F characters as 2 and everything else as 1. That is this article's assumption, not Google's formula. For borderline copy, confirm with the counter in the Google Ads editor.

[2] Write the prompt. The limits are left out on purpose. The product and advertiser are made up.

head.txt
Write Google responsive search ad copy in Korean for the product below.- 12 headlines and 4 descriptions.- Output one JSON object per line (JSON Lines): {"type": "headline", "text": "..."} or {"type": "description", "text": "..."}- No other text, no code fences. Product: Moonlight Farm tangerine gift set (fictional). 5 kg box, Jeju open-field grown, order before the holiday cutoff, free shipping nationwide.

The run below used the Korean version of this prompt, so the output is Korean.

console
$ claude -p --model sonnet --max-turns 1 < head.txt > out.1.jsonl$ head -3 out.1.jsonl{"type": "headline", "text": "달빛농원 제주 감귤 선물세트"}{"type": "headline", "text": "제주 노지 감귤 5kg 한 상자"}{"type": "headline", "text": "명절 선물, 감귤로 전하세요"}

claude -p answers once and exits; --max-turns 1 allows a single turn.

[3] Create the checker. It collapses whitespace, measures width, and finds identical text within the same type (ignoring case and trailing spaces).

check_ad.py
#!/usr/bin/env python3"""usage: check_ad.py ads.jsonl — RSA limits: headline 30, description 90, double-width chars count 2, duplicates"""import sys, json, unicodedata, collectionsLIMIT = {"headline": 30, "description": 90}def width(s):    return sum(2 if unicodedata.east_asian_width(c) in "WF" else 1 for c in s)rows = [json.loads(l) for l in open(sys.argv[1], encoding="utf-8") if l.strip()]seen = collections.defaultdict(list)for i, r in enumerate(rows):    seen[(r["type"], " ".join(r["text"].split()).casefold())].append(i)bad = 0for i, r in enumerate(rows):    t = " ".join(r["text"].split())    w = width(t)    errs = []    if w > LIMIT[r["type"]]:        errs.append(f"width {w} > {LIMIT[r['type']]}")    dup = [j for j in seen[(r["type"], t.casefold())] if j != i]    if dup:        errs.append("duplicate of #" + ",#".join(str(j) for j in dup))    print(f"#{i} {r['type'][:4]} w={w:<3} len={len(t):<3}", "FAIL " + "; ".join(errs) if errs else "ok", sep=" ")    bad += bool(errs)n = collections.Counter(r["type"] for r in rows)print(f"{n['headline']} headlines, {n['description']} descriptions, {bad} failed")sys.exit(1 if bad else 0)

[4] Run it.

console
$ python3 -I check_ad.py out.1.jsonl | grep -v ' ok$'; echo "exit ${PIPESTATUS[0]}"#12 desc w=92  len=55  FAIL width 92 > 90#15 desc w=96  len=55  FAIL width 96 > 9012 headlines, 4 descriptions, 2 failedexit 1

All 12 headlines passed (width 22–28); 2 of 4 descriptions went over. Both have len 55, so a plain len() check would have passed them against a limit of 90.

[5] Regenerate only the failed rows. Rerunning everything would change the rows that passed. State the counting rule in the prompt and attach each failed row's number, width and text.

prompt.2.txt
These ad descriptions exceed the character limit. Count each Korean, Chinese or Japanese character as 2, and Latin letters, digits, spaces and periods as 1. The total must be 90 or less.Keep the meaning, shorten, and rewrite. Output one JSON object per line: {"type": "description", "text": "..."} No other text. #12 (92) 제주 노지에서 자란 달빛농원 감귤을 5kg 한 상자에 담았습니다. 명절 선물로 마음을 전해 보세요.#15 (96) 햇빛과 바람으로 키운 제주 노지 감귤. 달빛농원 감귤 선물세트로 가족과 지인께 달콤함을 선물하세요.
console
$ claude -p --model sonnet --max-turns 1 < prompt.2.txt > out.2.jsonl$ python3 -I check_ad.py out.2.jsonl#0 desc w=85  len=51  ok#1 desc w=89  len=51  ok0 headlines, 2 descriptions, 0 failed

[6] Merge the two results by row number (replace #12 and #15) and check again.

console
$ python3 -I check_ad.py merged.jsonl | grep -v ' ok$'; echo "exit ${PIPESTATUS[0]}"12 headlines, 4 descriptions, 0 failedexit 0

[7] The model produced no over-length headline or duplicate, so edit merged.jsonl by hand to confirm those checks. Headline #1 was lengthened, and #4 was replaced with the same text as #8 plus a trailing space. These are not model errors.

console
$ python3 -I check_ad.py bad.jsonl | grep -v ' ok$'; echo "exit ${PIPESTATUS[0]}"#1 head w=41  len=26  FAIL width 41 > 30#4 head w=23  len=13  FAIL duplicate of #8#8 head w=23  len=13  FAIL duplicate of #412 headlines, 4 descriptions, 3 failedexit 1

Passing the check says nothing about ad policy review. Whether claims like free shipping or "order before the cutoff" are true is for the advertiser to confirm. The script does not check the minimum (3 headlines, 2 descriptions) or maximum (15 · 4) counts.

#google-ads#character-limit#python