Evaluating Lightweight Large Language Models on Constraint-Based Programming Tasks

    Lightweight language models offer lower inference costs and faster responses, but may be less reliable on complex reasoning and strict constraints. This article presents a practical evaluation framework covering instruction following, output completeness, constraint adherence, response performance, and verifiability, with examples from geometric construction and web page generation tasks. It also outlines automated checks, controlled experiments, and common evaluation mistakes.

    Why Lightweight Models Need Separate Evaluation

    Lightweight models are often selected for their lower inference costs and shorter response times. Common use cases include code completion, UI prototyping, and high-volume text processing. Compared with flagship models, they generally have smaller parameter counts and less training data, so differences become more visible in complex reasoning, long chains of constraints, and detailed instruction following.

    Many teams decide whether a model is “good enough” based on one or two examples. This can be misleading: a single response may happen to be correct or may only satisfy the visible requirements by chance. To determine whether a model can complete a task consistently, evaluation should be broken down into observable and reproducible dimensions.

    Designing the Evaluation Dimensions

    A practical evaluation framework usually covers five dimensions:

    1. Instruction adherence: Does the output follow every requirement in the prompt, including the operation sequence, permitted actions, and prohibited behaviors?
    2. Output completeness: Does the result address all requirements, or does it omit content, skip steps, or replace details with vague phrases such as “omitted”?
    3. Constraint deviation: Does the model introduce steps that were not requested or use additional techniques to produce a result that only appears correct?
    4. Response performance: Are time to first token, total completion time, and output speed stable? Does the model spend a long time reasoning without producing visible output?
    5. Verifiability: Can the result be checked quickly by a program or a human without relying primarily on subjective judgment?

    The third dimension is especially easy to overlook. A page may appear fully functional even though its implementation does not follow the required method. If an evaluation only examines the final visual result, it cannot reveal whether the model bypassed the task’s constraints.

    Example: Constraint-Based Geometric Construction

    Geometric construction tasks are useful for testing instruction following. These tasks often impose explicit procedural restrictions. For example, the model may be allowed to use only a straightedge and compass, construct the perpendicular bisector of two points first, and then determine the circle’s center from the intersection point. The prompt can also define rendering rules, such as requiring the compass to leave a trace while moving but retaining only the necessary parts of that trace.

    These constraints make “correctness” concrete. If the model introduces an unauthorized tool during an intermediate step or skips a required construction step, the result should be considered invalid even if it looks visually close to the expected output.

    When designing such tasks, consider the following principles:

    • Every operation should be independently checkable.
    • Clearly specify the permitted tools and prohibited methods.
    • Define checkable structural requirements for the final output, such as the types and quantities of SVG elements.
    • Avoid tasks that closely duplicate common examples, so that the model cannot rely primarily on memorized patterns.

    Automated Checks for Web Page Generation

    For frontend page-generation tasks, relying only on visual inspection is inefficient and can be affected by visual distractions. A more reliable approach is to convert structural requirements into rules and verify them with a script.

    The following simplified example checks whether generated HTML contains required elements and whether it uses prohibited external resources:

    1. import re
    2. REQUIRED_TAGS = ["canvas", "svg"]
    3. FORBIDDEN_PATTERNS = [r"<script\s+src=", r"https?://"]
    4. def check_html(html: str) -> dict:
    5. result = {"missing_tags": [], "violations": []}
    6. for tag in REQUIRED_TAGS:
    7. if not re.search(rf"<{tag}\b", html, re.IGNORECASE):
    8. result["missing_tags"].append(tag)
    9. for pattern in FORBIDDEN_PATTERNS:
    10. if re.search(pattern, html, re.IGNORECASE):
    11. result["violations"].append(pattern)
    12. result["passed"] = not result["missing_tags"] and not result["violations"]
    13. return result

    This type of check only covers structural issues. It cannot determine whether the geometric logic is correct. A second layer of validation is therefore needed, such as running the page in a browser, reading the coordinates of key nodes, and comparing them with theoretical values within an acceptable error range.

    Key Considerations for Controlled Comparisons

    To make model comparisons meaningful, the experiment should follow several principles.

    Control the variables. Use exactly the same prompt, input format, and context length for every model. If the conditions differ, the results cannot clearly demonstrate differences between the models themselves.

    Fix the sampling parameters. Temperature, maximum output length, and other relevant parameters should be standardized. If one model uses more conservative settings, its apparent stability may be artificially increased or reduced.

    Repeat the experiment. A single run is strongly affected by randomness. Each model should be tested multiple times. Record the pass rate, and describe latency using the median and percentiles rather than reporting only the best result.

    Record process data. Capture the request time, time to first output, completion time, and whether the model produces a prolonged blank interval. These measurements help assess the experience users will have in real-world use.

    Preserve the raw outputs. Store every result in full for later review. Some problems only become visible when the output is compared with the required steps line by line.

    Common Evaluation Errors

    Several misjudgments occur frequently in practical evaluations.

    Treating completion as correctness. A page that opens successfully or a graphic that looks symmetrical does not necessarily mean that the construction process was compliant. Both the process and the final result should be checked.

    Treating fluency as capability. Fast output does not necessarily indicate more accurate reasoning, and slow output does not necessarily indicate poor quality. Speed should be measured as an independent metric.

    Treating the length of the reasoning process as a measure of intelligence. A long reasoning sequence may reflect repeated trial and error rather than stronger understanding. The final result must be evaluated alongside the process.

    Ignoring timeouts and empty responses. If a model produces only reasoning content without a final answer, the calling system needs timeout and retry policies. These cases should be included in the failure rate rather than discarded.

    Conclusion

    Evaluating lightweight models requires turning the vague question of whether a model is “good enough” into specific, verifiable metrics. Teams should first identify the constraint types that matter most in their workflows, then build test sets containing both standard cases and boundary conditions. Automated checks should be combined with manual review, and the results should be recorded over time.

    A model is ready for production use in constraint-based workflows only when it performs consistently, produces verifiable outputs, and delivers acceptable response times. Evidence-based selection is more reliable than relying on a single demonstration and can significantly reduce the cost of later trial and error.