Understanding LLM Hallucinations and Safety Alignment: Causes, Types, and Engineering Practices

    This article explains why large language models behave differently on the same tasks and traces those differences to training data, alignment strategies, context window design, multimodal encoding, and safety policies. It breaks hallucinations into factual, instruction-following, and context-related types, describes how excessive safety alignment causes over-refusal along with mitigation techniques, and outlines methods for improving multimodal understanding. It closes with practical recommendations for developers, including capability matrices, retrieval augmentation, validation layers, and context structuring.

    1. Background: Why Similar Models Perform Differently

    In practice, users often notice that different large language models perform noticeably differently on the same task. Some answer conservatively and refuse frequently; others are stronger at interpreting image details but suffer from factual errors and unstable context memory. These differences are not simply a matter of “higher or lower capability.” They result from the combined effect of training data distribution, alignment strategies, context window design, multimodal encoding approaches, and safety policies.

    From an engineering perspective, model output can be viewed as a conditional probability process: generating the most likely token sequence given the context and system constraints. When context is insufficient, instructions are vague, or the request goes beyond the model’s knowledge boundary, the model tends to produce content that “looks reasonable.” This is one source of hallucinations.

    2. Causes and Types of Hallucinations

    2.1 Factual Hallucinations

    The model generates content that conflicts with objective facts, such as incorrectly attributing an image’s source, author, or series theme. These issues are more common in multimodal scenarios, because image recognition and knowledge retrieval are two separate pipelines. Without external knowledge verification, the model tends to “describe the image based only on the image.”

    2.2 Instruction-Following Hallucinations

    The model ignores constraints the user explicitly provided. For example, the user points out a key element in the image, yet the model sticks to its original judgment. This usually stems from biased attention allocation and conflicts with the system prompt.

    In long conversations, critical information from earlier turns gets diluted, leading to memory drift. The longer the context, the more easily the weight of key constraints is weakened by irrelevant content.

    3. Over-Refusal Caused by Safety Alignment

    Safety alignment is an important stage of model training, aimed at reducing the risk of harmful output. However, excessive alignment can cause the model to refuse compliant requests as well, for example misclassifying general technology deployment or operations configuration questions as high risk. In engineering practice, an “intent clarification plus scope limitation” approach can reduce the false refusal rate:

    1. Please treat this as general technical instruction. Discuss only publicly documented standard procedures, and do not involve any credentials, keys, or ways to bypass security mechanisms.

    In addition, splitting a request into several low-risk sub-questions is often more effective than asking one compound question all at once.

    4. Differences in Multimodal Understanding and How to Improve Them

    Image understanding tasks require the model to perform object detection, spatial relationship reasoning, and semantic interpretation at the same time. If the model focuses only on the main subject and ignores secondary elements, the result is an “incomplete explanation.” Ways to improve this include:

    • Explicitly listing the elements to observe in the prompt;
    • Asking the model to describe first and reason afterward, avoiding immediate conclusions;
    • Requiring visual evidence for key conclusions;
    • Using multiple rounds of follow-up questions to fill in details step by step.

    Example prompt:

    1. First describe each object, color, and spatial relationship in the image item by item, then give the overall meaning. If information is insufficient, explicitly state the uncertainty.

    5. Practical Recommendations for Developers

    1. Build a “model capability matrix”: evaluate models separately across dimensions such as factual question answering, long-form writing, code generation, and image understanding, rather than judging quality by a single metric.
    2. Introduce retrieval augmentation: connect factual questions to a knowledge base or search results to reduce the room for the model to improvise.
    3. Design a validation layer: apply rule-based checks or a second model review to critical outputs.
    4. Control context structure: place system constraints, user goals, and reference material in separate layers to reduce conflicts.
    5. Record failure samples: build a regression evaluation set and continuously refine prompts and workflows.

    6. Conclusion

    Performance differences across models are a reflection of their training objectives and alignment strategies. Developers should treat models as orchestratable components and build stable systems through prompt design, retrieval augmentation, and workflow validation. When enterprise-grade computing power, model services, and data governance capabilities are needed, architecture design can draw on the general cloud product capabilities offered by Baidu AI Cloud, improving overall application effectiveness while maintaining security and compliance.