Structure Adherence in LLMs for Requirements Document Writing

    This article examines how large language models handle structure adherence when expanding requirements documents, focusing on the difference between anchor-based expansion and reconstructive generation. It covers engineering techniques for hallucination suppression, including prompt constraints, deterministic structure validation, and retry fallback strategies. It also addresses stability requirements for multimodal table recognition and outlines a practical workflow that combines constrained generation, confidence thresholds, and human review to keep scope drift and uncertainty under control.

    Structure Adherence in LLMs for Requirements Document Writing

    1. Background: Why “Completion” Is Harder Than “Rewriting”

    During the requirements phase of software development, product managers and developers usually already have a rough feature list, for example one with only four top-level items: A, B, C, and D. The goal of introducing a large language model at this point is clear: fill in sub-items, boundary conditions, and acceptance criteria for each item without changing the existing structure.

    In engineering terms, this is constrained structured generation. The difficulty lies not in language fluency but in three areas:

    1. Structure preservation: The set of top-level items in the output must match the input exactly, with no deletions, merges, or additions.
    2. Semantic fidelity: Added content must trace back to the original items and must not introduce features absent from the input.
    3. Parseability: The output must keep a stable hierarchical format so it can be imported into a documentation system or converted into development tasks.

    A common pattern in the industry is that some models tend toward a “global rewrite,” reorganizing the information architecture based on their own interpretation, while others lean toward “local expansion,” strictly anchoring to the input skeleton. The former is useful in brainstorming scenarios but carries higher risk in requirements review, because the core asset of a requirements document is the already-agreed scope boundary.

    2. Comparing the Two Generation Behaviors

    To avoid pointing at specific products, we abstract the behavior into two strategies:

    • Strategy 1: Anchor-based Expansion

      Example output:

    1. A
    2. A1
    3. A2
    4. A3
    5. B
    6. B1
    7. C
    8. C1
    9. C2
    10. D
    11. D1
    12. D2
    • Strategy 2: Reconstructive Generation

      Example output:

    1. A
    2. A1
    3. C
    4. C1
    5. C2
    6. D
    7. D2
    8. E
    9. E1 (with an explanation that "E is derived from B and C3")

    The problem with Strategy 2 is that it deletes B, adds E, and provides a derivation-based explanation. For a requirements document, this is a combination of scope drift and hallucinated elaboration, and it significantly raises review costs.

    3. Engineering Techniques for Hallucination Suppression

    3.1 Prompt-Level Constraints

    Explicitly state in the system prompt that “only expansion is allowed; adding or removing top-level items is not,” and require the model to self-check before producing output. An illustrative prompt fragment:

    1. Rules:
    2. 1. The set of top-level items must match the input exactly;
    3. 2. Adding items that do not exist in the input is prohibited;
    4. 3. Only sub-items may be appended under each top-level item;
    5. 4. If information is insufficient, output "to be confirmed" and do not speculate.

    3.2 Structure Validation Layer

    Add deterministic validation on the application side instead of relying entirely on the model’s self-discipline:

    1. def validate_structure(src, out):
    2. src_keys = set(src.keys())
    3. out_keys = set(out.keys())
    4. assert out_keys == src_keys, f"Structure drift: missing {src_keys-out_keys}, added {out_keys-src_keys}"
    5. return True

    3.3 Retry and Fallback Strategy

    When validation fails, use a “degraded retry”: narrow the task granularity, complete each top-level item separately, and merge the results in code. This approach can significantly reduce the probability of structure drift, at the cost of more API calls and higher latency.

    4. Stability Requirements for Multimodal Recognition

    Another high-frequency scenario in the requirements phase is converting table screenshots into structured text (for example, a Markdown table) and then passing it to an AI coding tool to generate code. This scenario places dual demands on the model:

    1. Visual fact fidelity: Cell content must come from the image, with no fabricated rows or columns.
    2. Format determinism: Separators, alignment, and empty-value representation must stay consistent.

    Engineering recommendations include:

    • Image preprocessing: upscale, crop, and enhance contrast to reduce misrecognition of small text;
    • Explicit negative constraints: state in the prompt that “a certain module does not have a certain feature,” and require the model to answer “not detected”;
    • Cross-validation: sample the same image multiple times, and if results are inconsistent, mark them as low confidence and route them to manual confirmation;
    • Structured output: prefer an intermediate table representation and render it to Markdown in code, avoiding column misalignment caused by the model directly concatenating text.

    An illustrative intermediate representation:

    1. {
    2. "columns": ["Module", "Feature", "Notes"],
    3. "rows": [["A", "A1", ""], ["C", "C1", "To be confirmed"]]
    4. }

    5. Workflow Design for Adoption

    Embedding these capabilities into the development workflow forms a closed loop:

    1. Maintain the feature list baseline manually and put it under version control;
    2. Let the model perform only “sub-item expansion,” and merge output after structure validation;
    3. Enable multi-sampling and a confidence threshold when converting screenshots into structured data;
    4. Send low-confidence results to a manual review queue;
    5. Feed review conclusions back as input for improving prompt templates and validation rules.

    At the infrastructure level, general cloud capabilities can carry this workflow: object storage holds image and document versions, a message queue smooths out spikes for batch recognition tasks, a container platform hosts a stateless inference gateway, and logging plus monitoring with alerting track metrics such as the structure drift rate and the manual review rate.

    6. Conclusion

    In the strongly constrained scenario of requirements document writing, the value of a model depends on whether it respects the existing structure and whether it stays faithful to the input facts. Anchor-based expansion combined with deterministic validation, gradual retries, and human review is currently the more reliable engineering path; reconstructive generation is better suited to the divergent discussion stage of early requirements work rather than the finalization stage. For multimodal table recognition, replace one-shot text generation with a “verifiable intermediate representation plus a confidence threshold” to keep uncertainty within a manageable range.