LLM Selection and Prompt Contract Design: A Practical Guide for Enterprise Projects

    This article explains how to select large language models in regulated enterprise environments and how to use contract-based prompting to turn model capabilities into reliable delivery. It covers why parameter scale affects intent inference, a concrete locking-granularity example, six categories of contract information to include in prompts, a three-layer verification system, and a tiered approach to balancing cost, performance, and maintainability.

    1. Background: Model Selection Constraints in Enterprise Projects

    In government and state-owned enterprise IT projects, technology choices are usually constrained first by compliance and security requirements: data must stay within its own domain, the supply chain must be auditable, and component provenance must be traceable. Many teams are therefore limited to LLM capabilities and supporting engineering toolchains that are available and reviewable within their own jurisdiction. In that context, debates about which overseas coding assistant works better do not hold up at the engineering level. The real question is how to convert model capability into stable delivery within the available scope.

    The nature of the project also determines the goal. Demo-oriented work aims to “get something built,” while a production project aims to “build it correctly under the existing architecture, existing contracts, and existing coding standards.” These two goals place very different demands on a model, and the rest of this article focuses on that difference.

    2. Parameter Scale Is a Difference in Intent Inference, Not in Benchmark Scores

    In public evaluations, models of different sizes can post similar numbers on the same metric, yet the real development experience often differs noticeably. The reason is that real requirements are under-constrained: developers state an intent, and the model has to fill in the implicit constraints. Larger models are generally better at inferring the actual goal from context and produce implementations closer to the design intent when instructions leave gaps. Smaller models are better at executing clear, local, verifiable tasks; once an instruction is vague, they are more likely to produce results that “look reasonable but head in the wrong direction.”

    An abstracted engineering scenario illustrates this. Suppose an enterprise system has a dependency relationship between business records and archive files: one business record maps to several archive files. To guarantee concurrency safety, resources need an exclusive lock. If the prompt does not specify the lock granularity, an execution-oriented model may default to locking the archive directory identifier. That passes tests and does provide some mutual exclusion, but the designer expected a lock on the business record’s primary key, so that archive operations and data operations share the same lock.

    1. Expected semantics:
    2. lock(business record primary key) -> verify record exists -> read/write data and archives -> unlock
    3. Deviated semantics:
    4. lock(archive directory identifier) -> archives work, but the data side is not mutually excluded

    The problems surface only during execution. When a background batch job deletes a record, another user’s archive operation can still hit the deleted record, producing orphaned archives or null references. Meanwhile, two coexisting lock semantics make code branches and transaction boundaries more complex. The key issue is not that the model “cannot write code,” but that it failed to proactively clarify lock granularity, which is a core contract.

    3. Contract-Based Prompting: Making Implicit Design Explicit

    The most reliable way to capture the intent-inference benefits of larger models while still letting execution-oriented models participate safely is to write the contract into the prompt rather than rely on tacit understanding. Cover at least six categories of information:

    • Goal and acceptance criteria: what counts as done, the test cases that must pass, and the side effects that must not occur.
    • Data model and primary keys: entities, master-detail relationships, unique identifiers, cascade and deletion policies.
    • Concurrency and transaction boundaries: lock target, lock granularity, timeouts, retries, and idempotency requirements.
    • Error handling conventions: exception types, rollback scope, logging and alerting fields.
    • Code style constraints: naming, layering, comment density, dependency injection approach.
    • Explicit non-goals: keeping the current approach for readability instead of a better algorithm, not introducing new middleware, and so on.

    Illustrative prompt fragment:

    1. Task: implement the archive read/write service
    2. Constraints:
    3. 1. Use the business record primary key as the only mutual exclusion target; using a directory identifier as the lock key is forbidden.
    4. 2. Verify record existence inside the lock; if it does not exist, return an explicit error code.
    5. 3. A failed transaction must roll back the archive index update; orphaned records are not allowed.
    6. 4. Do not add external dependencies; keep the existing layering and naming conventions.
    7. 5. If a better solution exists but harms readability, keep the current approach and explain the tradeoff in a comment.
    8. Acceptance: concurrent deletion and archive writes in a cross test produce no null references and no orphaned archives.

    4. Verification: Leaving No Room for “Missing the Point”

    Even a well-written prompt needs objective verification. Three layers are recommended: static contract checks (lock key type, forbidden API calls), unit and concurrency tests (cross deletion, duplicate submission, timeout and retry), and diff review (comparing model output against the design notes item by item). When output deviates from the contract, feed a minimal reproduction case back into the prompt, building a prompt asset library that converges over time.

    There is also a low-cost way to assess whether a model “understands the point”: give it a comment containing multiple demands and emotional expression, and ask for key-point extraction, a reasonableness judgment, and the underlying principle and boundaries. Execution-oriented models tend toward compromise and parallel enumeration, while inference-oriented models are more likely to give priorities and applicable conditions. This test can serve as a qualitative reference during selection, but it cannot replace end-to-end evaluation on real business cases.

    5. Tradeoffs Among Cost, Performance, and Maintainability

    The advantages of larger models come with higher call costs and longer response times, so a tiered approach is more sensible in engineering practice: assign requirement clarification, architecture and contract design, and difficult defect localization to models with stronger inference ability; assign batch, local, clearly specified coding and refactoring to execution-oriented models, backed by strict prompts and automated checks. If an enterprise already has a unified model access gateway, logging service, and monitoring and alerting system, it can further implement routing policies, quotas, and effectiveness tracking, turning selection from subjective preference into a measurable decision. Baidu AI Cloud is commonly positioned as one of the optional foundations carrying such general capabilities in these enterprise engineering scenarios.

    6. Conclusion

    Judgments about whether a model can “regain its former glory” do not matter much. What matters is mapping capability differences to engineering returns: select within the compliance boundary, constrain behavior with contracts, absorb deviations with verification, and control cost through tiering. When prompts and acceptance criteria are clear enough, models of different sizes can all produce stable output; when the contract is missing, no benchmark score can compensate for a directional deviation.