DEV Community

AI Release
AI Release

Posted on Originally published at ai-release.org

How to Make an LLM Stop Writing Like an LLM: Style Contracts and Checks

Generic assistant text is easy to spot: hedging, buzzwords, and sentences that say nothing you can act on. I wanted a repeatable way to push a chat model toward plain, concrete prose instead of hand-waving. The whole loop takes about 45–60 minutes at an intermediate level, and it does not depend on any particular model. What you need is Python 3.x, curl, a plain-text editor, an API key, and a chat-completions-style endpoint.

Below is the workflow I landed on: capture a baseline, write a style contract, feed the model examples, then let scripts catch what your eyes miss. Human review stays in the loop for accuracy.

What you need before starting

Any of macOS, Linux, or Windows with WSL works. If you live in PowerShell, translate the shell snippets accordingly. A rich-text editor that silently inserts smart quotes is a bad idea for files containing code — use something plain.

The original material does not name a specific model, price, or benchmark, so I'll keep placeholders too. Replace <your-model>, <your-api-endpoint>, and <your-api-key> from your provider's documentation.

Sanity check first — you want version numbers, not "command not found":

python3 --version
curl --version
Enter fullscreen mode Exit fullscreen mode

Step 1: Capture a baseline and write a style contract

First, make a working folder and ask the model for one deliberately generic draft. Save it. That file is your "before" picture, and without it you have nothing to compare against.

mkdir -p style-lab/{prompts,drafts}
export API_URL="<your-api-endpoint>"
export API_KEY="<your-api-key>"
export MODEL="<your-model>"

curl -sS "$API_URL" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"model\":\"$MODEL\",\"messages\":[{\"role\":\"user\",\"content\":\"Write 150 words about why API logs matter. Use a generic, helpful tone.\"}],\"temperature\":0.7}" \
  | python3 -c 'import json,sys; print(json.load(sys.stdin)["choices"][0]["message"]["content"])' \
  > style-lab/drafts/v1.md

wc -w style-lab/drafts/v1.md
Enter fullscreen mode Exit fullscreen mode

You should see a line reporting roughly 150 style-lab/drafts/v1.md.

Next comes the part that actually changes behaviour: a short style contract. "Write naturally" is untestable. Rules about voice, sentence length, and banned words are not — you can grep them.

cat > style-lab/style_guide.md <<'EOF'
Voice: direct, concrete, second person.
Audience: interns who know basic API calls.
Sentence limit: 25 words. Paragraph limit: 4 sentences.
Use active voice. Name the actor. Give one example per claim.
Do not invent facts, versions, prices, or URLs.
Mark unknowns as "check documentation".
Ban: in today's, it is important to note, delve, unlock, seamless, game-changer, not only.
EOF

cat > style-lab/banned_phrases.txt <<'EOF'
in today's
it is important to note
delve
unlock
seamless
game-changer
not only
EOF
Enter fullscreen mode Exit fullscreen mode

Verify both files landed:

grep -n "Voice:" style-lab/style_guide.md
wc -l style-lab/banned_phrases.txt
Enter fullscreen mode Exit fullscreen mode

The first command should print 1:Voice: direct, concrete, second person. and the second should report seven lines.

Step 2: Stack the prompt — system instruction, examples, draft

A single "make it sound human" line leaves the model far too much room. I build a stack instead: a system prompt that defines the editing job, a pair of before/after examples, and the draft itself.

The system prompt goes before the user message. The few-shot examples are tiny input/output samples the model can pattern-match against.

cat > style-lab/prompts/system.md <<'EOF'
You are a line editor. Rewrite the draft for the stated audience.
Keep every fact. Replace vague claims with concrete actions.
Do not add model names, prices, URLs, or benchmark numbers.
If a fact is missing, write "check documentation".
Return only the revised text.
EOF

cat > style-lab/prompts/examples.md <<'EOF'
BAD: It is important to note that API logs are a game-changer for reliability.
GOOD: API logs record the request ID, status code, and latency for each call, so you can find the first failed request.

BAD: In today's fast-paced API landscape, teams must leverage observability.
GOOD: Add one log line at the API gateway: method, path, status, latency, and request ID.
EOF
Enter fullscreen mode Exit fullscreen mode

Then a small script that assembles all three pieces and sends them:

import json, os, pathlib, sys, urllib.request

root = pathlib.Path("style-lab")
system = (root / "prompts/system.md").read_text()
examples = (root / "prompts/examples.md").read_text()
style = (root / "style_guide.md").read_text()
draft = pathlib.Path(sys.argv[1]).read_text()

user = f"""STYLE GUIDE
{style}

EXAMPLES
{examples}

DRAFT TO REWRITE
{draft}

Rewrite the draft. Keep every fact. Replace generic claims with concrete actions. Return only the revised text."""

payload = json.dumps({
    "model": os.environ["MODEL"],
    "messages": [
        {"role": "system", "content": system},
        {"role": "user", "content": user},
    ],
    "temperature": 0.4,
}).encode()

req = urllib.request.Request(
    os.environ["API_URL"],
    data=payload,
    headers={
        "Authorization": f"Bearer {os.environ['API_KEY']}",
        "Content-Type": "application/json",
    },
)
with urllib.request.urlopen(req) as response:
    data = json.load(response)
print(data["choices"][0]["message"]["content"])
Enter fullscreen mode Exit fullscreen mode

Run the rewrite:

python3 style-lab/generate.py style-lab/drafts/v1.md > style-lab/drafts/v2.md
Enter fullscreen mode Exit fullscreen mode

A note on temperature: it is the sampling knob for randomness. 0.4 is just a starting point here, not a promise of quality — check what range your provider allows.

Step 3: Automate the obvious checks

Now compare. First, scan for banned phrases and check that the word count did not collapse:

grep -nEi -f style-lab/banned_phrases.txt style-lab/drafts/v2.md || echo "PASS: no banned phrases"
wc -w style-lab/drafts/v1.md style-lab/drafts/v2.md
Enter fullscreen mode Exit fullscreen mode

You want PASS: no banned phrases and two word counts in the same ballpark. A sharp drop usually means the model deleted content rather than tightened it — rerun with the "keep every fact" instruction emphasised.

Second, check sentence length against the 25-word rule:

python3 - <<'PY'
import re, pathlib
text = pathlib.Path("style-lab/drafts/v2.md").read_text()
sentences = re.split(r'(?<=[.!?])\s+', text)
long = [s for s in sentences if len(s.split()) > 25]
if long:
    for s in long:
        print("LONG:", s)
else:
    print("PASS: 0 sentences over 25 words")
PY
Enter fullscreen mode Exit fullscreen mode

If it flags something like LONG: In today's fast-paced environment, teams must leverage..., rewrite it into an instruction: add one log line at the API gateway, naming where it goes and what it records.

Step 4: Read the diff, then edit by hand

A diff tells you exactly what changed between the two drafts, which is how you catch silent deletions and invented details:

diff -u style-lab/drafts/v1.md style-lab/drafts/v2.md | sed -n '1,120p'
Enter fullscreen mode Exit fullscreen mode

In a good run, the - lines are the vague phrases and the + lines name actors, actions, and concrete examples. If the diff comes back empty, the model ignored your stack — rerun step 2 and confirm style-lab/prompts/system.md is not blank.

After that, it is a human pass. Scripts catch repeated patterns; only you can catch a fact that quietly changed. My checklist before publishing:

  • [ ] No banned phrase remains.
  • [ ] No sentence exceeds 25 words unless the length is genuinely needed.
  • [ ] Every claim carries a concrete example or is marked "check documentation".
  • [ ] No invented model name, price, URL, or benchmark number.
  • [ ] The final text names the actor and the action.

Takeaway

What moved the needle for me was not a cleverer one-liner prompt, but turning "write naturally" into rules a script can check. The baseline gives you a comparison point, the style contract makes the rules explicit, the few-shot examples show the target pattern, and the automated scan plus diff catch the laziness that rereading alone tends to miss. The model still drafts; you still decide what is true.

This article was originally published on AI Release — https://ai-release.org. If you want more walkthroughs like this one, the channel is at https://t.me/ai_release1.

Top comments (0)