Split long sentences with AI without losing the conditions
AI can drop "only if" and "However," when it splits long sentences. Cap the length in the prompt, then measure sentence length and markers with a script.
A notice came back with "I run out of breath reading it." The sentences average 226 characters, and the longest is 297. Hand the text below to an AI to split, then check what survived the split.
[1] The input is a made-up office notice in four paragraphs: 8 sentences averaging 225.9 characters. It contains "only if" twice, "only when" once and "However," twice.
Starting next month, the shared meeting rooms must be booked on the internal booking sheet by 6 PM the day before use, and if a meeting that was held without a booking overlaps with a booked one, the team that booked first has priority, so the later team must leave the room right away. A booking can last at most two hours, and when the same team makes a fourth request in the same week, it is confirmed only after the General Affairs team approves it. Laptops and projectors must both be signed out at the General Affairs desk by writing down your name and the planned return date, and since every day of late return pushes your next loan request back by two days, please tell us before the return date if your schedule changes. However, equipment for external events can be borrowed only if it was requested at least one week before the event, and damaged equipment is removed from the loan list until the repair is finished. Travel expenses are settled only if the receipt photos and the trip report are submitted together within ten days of returning from the trip, and after that deadline they are not added to the next month's pay and a separate application is needed, so it is safer to photograph receipts on the spot. Taxi fares are accepted only when public transport has stopped running or you are carrying a lot of luggage, and in other cases they may be rejected even with a written reason. This notice applies from the first day of next month, but meetings already booked and equipment already on loan are handled the old way, and questions about the new rules can be posted on the General Affairs board, where the person in charge will reply within two business days after checking. However, equipment that is due back this month must be returned by the end of the month regardless of the new rules.[2] The prompt gives one rule per risk. The length is a number, and the conditions are named by the exact words. Numbered steps are the format the Claude prompting guide recommends when order and completeness matter. The document goes inside a tag so the model can tell it from the instructions.
Split the long sentences in the text inside <document> into shorter ones. Do not change the meaning. Rules:1. Every sentence must be 120 characters or fewer, spaces included.2. If a sentence joined a cause and its result, keep the relation with a connector such as "so" or "therefore".3. Keep conditions and exceptions ("only if", "only when", "However,") and attach them to the same statement they limited.4. Keep numbers, deadlines, names and team names exactly as written. Do not add or remove information.5. Keep the paragraph count and order. Add no headings.6. Output only the rewritten text, with no explanation. <document>[3] Append the text and the closing tag, then run it. --tools "" turns off built-in tools, --strict-mcp-config drops connected MCP tools, and --setting-sources "" skips your settings and CLAUDE.md files. The same prompt pastes into ChatGPT.
$ (cat head.en.txt doc.en.txt; echo "</document>") > prompt.en.txt$ claude -p --model claude-sonnet-5-5 --max-turns 1 --tools "" --setting-sources "" --strict-mcp-config < prompt.en.txt > out.en.1.txtParagraph 3 came back like this. Causes and results are still joined with "Therefore,", and no headings were added.
Travel expenses are settled only if the receipt photos and the trip report are submitted together. They must be submitted within ten days of returning from the trip. After that deadline, the expenses are not added to the next month's pay, and a separate application is needed. Therefore, it is safer to photograph receipts on the spot. Taxi fares are accepted only when public transport has stopped running or you are carrying a lot of luggage. In other cases, they may be rejected even with a written reason.[4] Measure it. This script splits on whitespace after a period, counts the sentence lengths, and counts how often each marker word appears before and after. A marker that disappears prints LOST and exits with 1.
#!/usr/bin/env python3"""usage: check.py before.txt after.txt limit marker [marker ...]"""import re, sysdef read(p): return " ".join(open(p, encoding="utf-8").read().split())def lens(t): return [len(s) for s in re.split(r"(?<=[.!?])\s+", t) if s]a, b, limit = read(sys.argv[1]), read(sys.argv[2]), int(sys.argv[3])for name, t in (("before", a), ("after", b)): L = lens(t) print(f"{name}: {len(L)} sentences, avg {sum(L)/len(L):.1f}, max {max(L)}, over{limit} {sum(x > limit for x in L)}")lost = 0for m in sys.argv[4:]: na, nb = a.count(m), b.count(m) lost += nb < na print("OK " if nb >= na else "LOST", repr(m), f"{na} -> {nb}")sys.exit(1 if lost else 0)$ python3 -I check.py doc.en.txt out.en.1.txt 120 "only if" "only when" "However,"before: 8 sentences, avg 225.9, max 297, over120 7after: 22 sentences, avg 82.6, max 118, over120 0OK 'only if' 2 -> 2OK 'only when' 1 -> 1OK 'However,' 2 -> 3Two things stand out. The conditions all survived, and no sentence is over the 120-character cap (the longest is 118). The model does not count characters, so a cap is a request, not a guarantee; that is why the script counts. The second run was also under the cap (23 sentences, longest 118) and differed from the first mainly in how the sentences were cut.
The other point: However, went from 2 to 3. The model rewrote the "but" in the last paragraph as a "However," of its own. The check only catches markers that vanish, so a marker that appears is something to read.
[5] Read what the script cannot see. In the original, "settled only if the receipt photos and the trip report are submitted together within ten days of returning" is one condition. In the output above the first sentence keeps "only if" and both documents, but "within ten days" moved to the next sentence ("They must be submitted within ten days…"). Read alone, the first sentence no longer says by when, and a word count will not notice. If you want the deadline kept inside, add a line to rule 3:
Keep what the condition requires (what, by when) inside the sentence that contains "only if".[6] Sentences like "Therefore, the later team must leave the room right away." depend on the sentence before them. That is fine in a notice, but read them in order before you paste the result into the document.
For a word-level diff of the before and after, see reviewing AI edits with a word diff.