A Practical Guide to LLM Mathematical Reasoning and Instruction Following

    This article presents a practical framework for evaluating and deploying large language models (LLMs) on mathematical reasoning and instruction-following tasks. It explains why single impressive demos often fail to translate into stable production behavior, then walks through a reproducible evaluation setup with layered tasks, metrics, and a sample record table. It also covers prompt engineering for complex constraints, root causes and mitigation of rising refusal rates, quota and cost management strategies, and specialized practices for auditable mathematical proofs. The goal is stable, reproducible, and auditable output under resource constraints.

    1. Background: From a Single Impressive Run to Reliable Production Use

    In real engineering and research settings, LLM behavior often shows a clear long-tail pattern: a single demo may look impressive, but after dozens of consecutive runs, fluctuations in stability, instruction following, and refusal tendency quickly amplify. Three representative issues stand out in the original discussion:

    • Output quality varies across runs.
    • Adherence drops for complex constraints (for example, “write this as lecture notes in English,” “use a specific layout format,” or “provide a complete proof”).
    • Refusal rates rise in sensitive or high-risk semantic contexts, interrupting otherwise legitimate tasks.

    For these reasons, a model should not be judged on a single capability point. Instead, use a four-dimensional framework: capability, stability, controllability, and cost. The sections below expand on each layer.

    2. Building a Reproducible Evaluation Framework

    2.1 Layered Task Design

    Split tasks into three layers:

    • L1 (Basic): definition restatement, format conversion, and simple derivations, used to verify instruction following and format stability.
    • L2 (Composite): stacked constraints, such as “prove a proposition + output in English + lecture-note structure + citation numbering rules.”
    • L3 (Open-ended): proofs of mathematical propositions without a given standard answer, solution design, and code refactoring, used to observe exploration depth and self-correction.

    2.2 Metric Definitions

    • Instruction-following rate: the proportion of constraints fully satisfied (format, language, length, and structure scored separately).
    • Refusal rate: the proportion of legitimate requests that are refused or evaded, bucketed by semantic category.
    • Consistency: the variance across repeated runs of the same prompt, measured via structural similarity and agreement on key conclusions.
    • Verifiability: for proof tasks, introduce checkable intermediate steps rather than judging only the final answer.

    2.3 Sample Evaluation Record Table

    1. task_id | layer | constraints | pass | refusal | latency | tokens
    2. T-001 | L2 | lang=en,latex,proof| 0.6 | 0.05 | 42s | 18k
    3. T-002 | L3 | open_proof | 0.35 | 0.12 | 96s | 47k

    3. Prompt Engineering Under Complex Constraints

    3.1 Structuring Constraints

    Turning natural-language constraints into a field-based checklist significantly improves adherence:

    1. {
    2. "task": "prove_statement",
    3. "output": {"language": "en", "format": "lecture_notes", "math_env": "latex"},
    4. "constraints": ["no_external_lookup", "complete_proof", "numbered_sections"],
    5. "acceptance": ["theorem_statement", "lemmas", "final_proof"]
    6. }

    3.2 Layering Context

    Place “long-term rules,” “task instructions,” “reference material,” and “output templates” in separate zones to avoid cross-contamination. For long-document tasks, first have the model produce and confirm an outline, then expand section by section. This noticeably reduces off-topic drift and format drift.

    3.3 Self-Check Loop

    Require the model to output a “self-check list” at the end, comparing results against each constraint. In practice, a second call can act as a “reviewer” that only proposes edits rather than rewriting the full text, which controls cost and variance.

    4. Diagnosing and Mitigating Rising Refusal Rates

    Higher refusal rates usually come from three sources: semantic trigger words, accumulated context risk, and safety policies’ conservative stance toward “executable details.” Mitigation approaches include:

    1. Semantic de-sensitization: rewrite the request as a goal-oriented description that emphasizes legitimate use and an academic or engineering context.
    2. Task decomposition: split an “overall request” into “analyze-design-verify” steps to lower per-step risk density.
    3. Explicit boundaries: state in the prompt that uncontrollable content will not be output, only verifiable intermediate results.
    4. Sampling strategy: for high-risk buckets, lower the temperature and enable structured output to reduce trigger probability.

    Note that safety policies cannot and should not be bypassed. On the engineering side, improve pass rates through legitimate and compliant task design.

    5. Quota and Cost Management: Spend Compute Where It Matters

    Under credit or quota limits, cost overruns often stem from “long chain of thought + large context + multiple retries.” Consider these strategies:

    • Tiered routing: send simple tasks to lightweight models and complex proofs to high-capability models.
    • Budget caps: set token and turn limits per task, with automatic downgrade or termination when exceeded.
    • Cache reuse: apply prefix caching to identical prefixes (system rules, reference material) to reduce repeated billing.
    • Incremental generation: generate long lecture notes section by section and persist them, so a failure only reruns a single section.
    • Asset accumulation: turn successful prompts and output templates into internal assets to reduce trial and error.

    Illustrative pseudocode:

    1. def run_with_budget(task, budget):
    2. plan = model.plan(task, max_tokens=budget*0.1)
    3. for section in plan.sections:
    4. if budget.used > budget.limit: return degrade(task)
    5. budget.spend(run_section(section))
    6. return assemble(plan)

    6. Specialized Practices for Mathematical Proofs

    For advanced math tasks, the key is not the “final answer” but an “auditable reasoning chain.” Recommended steps:

    1. First formalize the proposition and known lemmas, and have the model list a dependency graph.
    2. Prove step by step, annotating the theorem and premises used at each step.
    3. Add a “counterexample check” step, letting the model attempt to construct counterexamples to self-verify rigor.
    4. Finally, unify the layout output to ensure consistent formula numbering and references.

    Even if model capability fluctuates slightly, this workflow guarantees overall quality through local retries.

    7. Selection Conclusions and Deployment Recommendations

    Overall, model capability should be evaluated within a specific task distribution: on open math problems, gaps between models are significant; on instruction following and architectural stability, differences are equally clear. Teams should build their own evaluation sets and cost models rather than relying on a single experience. A recommended rollout path: first build the evaluation set, then implement tiered routing, and finally solidify prompts and template assets. Only this yields stable, reproducible, and auditable output under quota constraints.