How to Evaluate LLM Writing Ability and Choose the Right Model: A Practical Guide

    This guide breaks LLM writing ability into measurable metrics, explains how to match models to specific writing scenarios, and provides reference Python code for calling a writing API and running evaluations. The thresholds it suggests are starting points that should be adjusted to your business risk.

    Introduction: Why Writing Quality Needs Measurable Criteria

    When choosing a model for writing, teams often rely on public leaderboards or a few sample texts. These methods do not answer the question that matters most to a team: can a model consistently meet the standard for its own genre, language, and length? This article breaks writing ability into measurable metrics, explains how to match models to scenarios, and provides reference code for calling and evaluating a model. The thresholds in this article are starting points. Adjust them based on your business risk.

    1. How to Define and Measure Writing Ability

    Descriptions such as “inner autonomy” are hard to verify. This article uses the following actionable metrics instead.

    Metric Definition Measurement method Example threshold
    Sentiment label consistency Share of outputs whose sentiment matches the prompt’s requirement 100 samples. Two annotators label each sample independently, and only consistent labels are kept. ≥85%
    Constraint satisfaction rate Share of outputs that meet all constraints in the prompt, including word count, grammatical person, point of view, and banned words At least 50 prompts with multiple constraints, checked against each rule ≥80%
    Adversarial prompt pass rate Share of outputs that handle contradictory or vague requirements reasonably and satisfy the parts that can be satisfied 30 adversarial prompts, judged manually ≥75%
    Multilingual coverage rate Pass rate for each target language and each genre A matrix of languages by genres, with at least 30 samples per cell ≥75% per cell
    Long-context consistency Share of cases where names, timelines, and settings remain correct after a multi-turn conversation Check against a settings sheet at turns 5, 10, and 20 ≥90% at turn 20

    1.1 Human Scoring Rubric

    Score each text on four dimensions, from 1 to 5 for each.

    • Sentiment accuracy: The emotional progression matches the prompt and does not drift noticeably.
    • Plot coherence: Cause and effect hold across the text, and character motivations do not shift abruptly.
    • Language quality: Sentences read naturally, without repeated stock phrases.
    • Style fit: The text matches the specified form and the target readers.

    Two reviewers score each text independently. Calculate Cohen’s kappa. If it is below 0.6, revise the scoring guidelines before continuing the evaluation.

    1.2 Measurement Notes

    • When comparing models, keep temperature, top_p, and the prompt version fixed. Otherwise, you are comparing parameters, not models.
    • Use the same prompt set for all candidate models, and record each model’s name and version.
    • Small sample sizes can produce differences caused by random variation. If two models differ by only a few percentage points, increase the sample size before drawing conclusions.
    • Do not use the same model for generation and scoring.

    2. How to Choose a Model for Each Scenario

    Model rankings change with each version, so this article does not rank specific models. Base your selection on the metrics in Section 1.

    Scenario Key capability Metrics to check first Selection notes
    Content marketing and social media copy Varied styles, short length, fast responses Sentiment label consistency, style fit Latency and unit cost matter most. Start with a general model plus style examples. Consider fine-tuning only if results fall short.
    Long-form worldbuilding (science fiction, fantasy) Long-context memory, no drift in settings Long-context consistency, plot coherence Test with the context length you can actually use, not the advertised window.
    Multilingual expansion Stable quality across languages Multilingual coverage rate Evaluate each language separately. Do not use English results to represent other languages.
    Official documents, manuals, and other strict texts Controlled output boundaries Constraint satisfaction rate Add rule-based checks and manual review.

    2.1 Selection Decision Order

    1. Is a compliance requirement mandatory? If yes, first filter for candidates that meet the constraint satisfaction rate target.
    2. Does the project target more than one language? If yes, set multilingual coverage as a hard requirement.
    3. Is there a need for serialized long-form content? If yes, test long-context consistency.
    4. Among the candidates that pass, compare cost, p95 latency, and cost per output.

    2.2 Common Mistakes

    • Drawing conclusions from one or two samples. Samples can happen to match or miss expectations by chance.
    • Inferring ability from nominal specifications. Parameter count and context window size do not directly indicate writing quality.
    • Generalizing results from one language to all languages.

    3. How to Call a Writing API Safely

    The code below is a reference implementation. Endpoint paths and field names should follow the official documentation of the provider you choose. The code assumes the API uses the common chat/completions format. If a provider uses different fields, change only the payload and the response parsing. The code runs on Python 3.9 or later with requests 2.31 or later.

    1. import os
    2. import time
    3. import requests
    4. API_BASE = os.environ["LLM_API_BASE"] # e.g. https://provider.example.com/v1
    5. API_KEY = os.environ["LLM_API_KEY"] # Read only from environment variables
    6. MODEL = os.environ.get("LLM_MODEL", "your-model-name")
    7. HEADERS = {"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"}
    8. TIMEOUT_SECONDS = 30
    9. MAX_RETRIES = 3
    10. RETRYABLE_STATUS = {429, 500, 502, 503, 504}
    11. def generate_text(prompt, temperature=0.8, max_tokens=1024):
    12. """Call the chat completions endpoint. Timeouts, connection errors, rate limits, and server errors are retried with exponential backoff."""
    13. url = f"{API_BASE}/chat/completions"
    14. payload = {
    15. "model": MODEL,
    16. "messages": [{"role": "user", "content": prompt}],
    17. "temperature": temperature,
    18. "top_p": 0.9,
    19. "max_tokens": max_tokens,
    20. }
    21. last_error = None
    22. for attempt in range(1, MAX_RETRIES + 1):
    23. try:
    24. resp = requests.post(url, headers=HEADERS, json=payload, timeout=TIMEOUT_SECONDS)
    25. if resp.status_code in RETRYABLE_STATUS:
    26. last_error = f"HTTP {resp.status_code}"
    27. else:
    28. resp.raise_for_status() # Other 4xx errors are raised immediately without retry
    29. return resp.json()["choices"][0]["message"]["content"]
    30. except (requests.exceptions.Timeout, requests.exceptions.ConnectionError) as e:
    31. last_error = str(e)
    32. if attempt < MAX_RETRIES:
    33. time.sleep(2 ** attempt)
    34. raise RuntimeError(f"Still failed after {MAX_RETRIES} retries: {last_error}")
    35. def generate_long_text(chapter_goals):
    36. """Generate text chapter by chapter. After each chapter, compress its key points and pass them to the next chapter as context. This reduces the risk of the model forgetting settings in long text."""
    37. chapters, memory = [], "(none)"
    38. for idx, goal in enumerate(chapter_goals, 1):
    39. prompt = f"Summary of previous chapters and settings: {memory}\nPlease write chapter {idx}. Requirements: {goal}"
    40. text = generate_text(prompt, temperature=0.8, max_tokens=1500)
    41. chapters.append(text)
    42. memory = generate_text(
    43. f"Summarize the character states and key plot points in the following chapter in no more than 200 words, for use in later chapters:\n{text}",
    44. temperature=0.2,
    45. max_tokens=300,
    46. )
    47. return chapters
    48. if __name__ == "__main__":
    49. demo = "Write an opening of about 200 words for a science fiction story. The protagonist feels both envy and deep affection for their partner. Keep the tone restrained."
    50. print(generate_text(demo, temperature=0.9))

    3.1 Temperature Guidelines

    In the code, top_p is fixed at 0.9. When tuning, change only temperature. Adjusting both sampling parameters at once makes results harder to predict.

    Task Temperature Notes
    Official documents and manuals 0.1 to 0.3 Lower randomness and prioritize constraint compliance
    Marketing copy 0.6 to 0.8 Balance variety and control
    Creative writing 0.8 to 1.0 High randomness, requires manual review

    3.2 Key and Data Security

    • Read API keys only from environment variables or a secrets management service. Never store them in code or configuration files, or commit them to version control.
    • Rotate keys regularly. Revoke a key immediately if it may have leaked.
    • Mask the Authorization header in logs. Redact personal identifiers in user input, such as phone numbers and national ID numbers, before writing to logs.
    • Escape model output before rendering it on the front end to prevent script injection.
    • Do not include real customer data in prompts unless compliance approval has been obtained.
    • Generation requests have no side effects, but retries add cost and latency. Always set a maximum number of retries.

    4. How to Build a Continuous Evaluation Loop

    4.1 Automated Evaluation Checklist

    Item Requirement
    Sample size At least 200 samples per scenario, stratified by genre and language
    Scoring dimensions Sentiment accuracy, constraint satisfaction, plot coherence, and language quality, each scored from 1 to 5
    Judge model Use a model from a different vendor or a different version than the model under test, to avoid self-evaluation bias
    Consistency check Have humans re-score a 10% sample and calculate agreement. If agreement falls below the threshold, revise the scoring prompt.
    Log fields Request ID, model name and version, temperature, top_p, prompt version, redacted output, scores for each dimension, latency, token count, and timestamp
    Regression cycle Run a full regression whenever the model version or prompt changes

    4.2 Evaluation Loop

    1. Each time a prompt or model version changes, run the full regression set.
    2. After automatic scoring, send samples that fall below the threshold to a manual review queue.
    3. Feed review results back to improve prompts or build fine-tuning data.
    4. Review metric trends weekly. If a key metric declines for two consecutive cycles, roll back the prompt or model version.

    4.3 Scope and Risks

    • Evaluation results apply only to the languages, genres, and lengths that were tested. Do not generalize them to other scenarios.
    • Results may change after a provider updates a model version. Re-evaluate after each update.
    • Judge models have their own biases. Spot-check key conclusions manually.
    • Generated text may resemble training data. Run originality checks before publication.
    • Generated content may contain factual errors or inappropriate statements. Review it before publishing.
    • The example thresholds in this article do not come from an industry standard. Set your own thresholds based on business risk.