Score the Readability of an AI Draft with textstat
Compare two AI drafts of the same announcement with textstat: average sentence length, Flesch score and grade level. See why scores break on Korean.
You asked an AI to "make it easier to read." Did it? Average sentence length and the Flesch score turn that into a number. For a similar script-based check on length and duplicates, see Check AI meta descriptions for length and duplicates.
[1] Create a virtual environment in the project and install textstat.
$ python3 -m venv .venv$ .venv/bin/pip install textstat$ .venv/bin/pip list | grep -i -E 'textstat|pyphen'pyphen 0.18.1textstat 0.7.13[2] Generate the same announcement twice. The first draft gets only the facts. The second is the first draft rewritten for an 8th-grade reader, under 15 words per sentence on average, same facts. The app and features are made up.
Write a product update announcement for customers of a small file-sync app called "SyncNest". The update (version 3.2) adds offline folders, faster uploads of large files, and fixes a bug where shared links expired early. About 180 words, plain prose, no headings, no bullet lists. Output only the text.$ claude -p --model sonnet --max-turns 1 < p1.txt > en.1.txt$ { echo 'Rewrite the announcement below so an average 8th-grade reader finds it easy: sentences under 15 words on average, everyday words, same facts, no new claims. Plain prose, no headings or lists. Output only the text.'; echo; cat en.1.txt; } > p2.txt$ claude -p --model sonnet --max-turns 1 < p2.txt > en.2.txt[3] Write a script that prints sentence count, word count, average sentence length (words_per_sentence), Flesch Reading Ease, Flesch-Kincaid grade, Gunning Fog and ARI.
#!/usr/bin/env python3"""usage: score.py FILE... — textstat scores per file"""import sys, textstatprint(f"{'file':<10}{'sent':>5}{'words':>6}{'w/sent':>8}{'FRE':>7}{'FKGL':>6}{'fog':>6}{'ARI':>6}")for p in sys.argv[1:]: t = open(p, encoding="utf-8").read() print(f"{p:<10}{textstat.sentence_count(t):>5}{textstat.lexicon_count(t):>6}" f"{textstat.words_per_sentence(t):>8.1f}" f"{textstat.flesch_reading_ease(t):>7.1f}{textstat.flesch_kincaid_grade(t):>6.1f}" f"{textstat.gunning_fog(t):>6.1f}{textstat.automated_readability_index(t):>6.1f}")[4] Score the two English drafts.
$ .venv/bin/python -I score.py en.1.txt en.2.txtfile sent words w/sent FRE FKGL fog ARIen.1.txt 12 203 16.9 65.5 8.3 10.1 9.5en.2.txt 20 196 9.8 86.8 3.6 4.7 4.0Average sentence length dropped from 16.9 to 9.8 words and Flesch Reading Ease rose from 65.5 to 86.8. Higher is easier; the textstat README puts 60–69 at Standard and 80–89 at Easy. FKGL is a US grade level. The prompt asked for 8th grade, and the second draft landed at 3.6, well below that.
[5] Run the same script on two Korean drafts of the same request (about 300 characters each).
$ .venv/bin/python -I score.py ko.1.txt ko.2.txtfile sent words w/sent FRE FKGL fog ARIko.1.txt 7 81 11.6 110.5 0.7 4.6 -1.3ko.2.txt 11 78 7.1 115.0 -1.0 2.8 -3.6Flesch is above 110 and the grade is zero or negative. That does not mean the Korean text is that easy. The English formulas rely on syllable counts, and the syllables come out like this:
$ .venv/bin/python -I -c "import textstat; print(textstat.syllable_count('싱크네스트'), textstat.syllable_count('synchronization'))"1 5싱크네스트 has five syllables but counts as 1. The first draft's syllable count (81) equals its word count (81), which fits. Fewer syllables push every score toward "easy."
[6] Try set_lang with Korean.
$ .venv/bin/python -I -c "import textstat; textstat.set_lang('ko'); print(textstat.syllable_count('안녕 하세요'))"…KeyError: NoneVersion 0.7.13 does not accept ko and stops with KeyError: None. The README's language table does not list Korean either (Flesch Reading Ease: en, de, es, fr, it, nl, pl, ru). For Korean, compare only sentence count and character count. The sentence counts above (7 and 11) matched a manual count of both Korean drafts.
[7] English input can also miscount sentences. A version number in the second sentence made sentence_count return 1.
$ .venv/bin/python -I -c "import textstatfor s in ['Version three is out. See the notes.','It is out. See v3.2.1 notes.']: print(textstat.sentence_count(s), s)"2 Version three is out. See the notes.1 It is out. See v3.2.1 notes.Release notes full of version numbers can show a longer average sentence than the real one. Count sentences by hand once to check. The cause was not investigated.