Improve GitLab Duo MR Review error handling for schema formatting
### Summary When a `.gitlab/duo/mr-review-instructions.yaml` file contains YAML that doesn't match the expected schema, GitLab Duo MR Review fails with a generic "I have encountered some problems while I was reviewing. Please try again later." message instead of providing helpful validation feedback about the malformed configuration. The underlying cause is a `NoMethodError: undefined method 'strip' for nil:NilClass` in `ee/lib/gitlab/llm/templates/review_merge_request.rb:73` when the `instructions` field is missing or nil due to schema mismatch. This was reported by a customer in [this zendesk ticket](https://gitlab.zendesk.com/agent/tickets/689017) ### Steps to reproduce 1. Create a `.gitlab/duo/mr-review-instructions.yaml` file with an incorrect schema format, for example: ```yaml version: 1 instructions: - name: "View Files Validation" description: "Validate .viewYml files for structural integrity" applies_to: file_patterns: - "**/*.viewYml" rules: - name: "No Development Folder References" severity: error description: "Views must not reference items in Development folders" check: | Search for cache dependencies containing 'development' in their paths. ``` 2. Create a merge request in the project 3. Trigger GitLab Duo MR Review ### Example Project <!-- Customer project - cannot be shared publicly --> ### What is the current *bug* behavior? GitLab Duo posts a comment with: > I have encountered some problems while I was reviewing. Please try again later. Sidekiq logs show: ``` "exception.class":"NoMethodError" "exception.message":"undefined method `strip' for nil:NilClass" "exception.backtrace":["ee/lib/gitlab/llm/templates/review_merge_request.rb:73:in `block in format_custom_instructions_list'"...] ``` ### What is the expected *correct* behavior? GitLab Duo should: 1. Validate the YAML schema before attempting to process custom instructions 2. Provide a clear, user-friendly error message indicating the configuration file format is incorrect 3. Point users to documentation showing the correct schema format Expected schema format: ```yaml version: 1 instructions: - name: "View Files Validation" instructions: | Search for cache dependencies containing 'development' in their paths. Flag any references to Development folders as policy violations. fileFilters: - "**/*.viewYml" ``` ### Relevant logs and/or screenshots ```json { "severity": "ERROR", "time": "2026-01-26T19:52:30.949Z", "correlation_id": "01KFXXTPEE85M42BX2PZQTQ0JH", "meta.caller_id": "Llm::CompletionWorker", "meta.feature_category": "ai_abstraction_layer", "exception.class": "NoMethodError", "exception.message": "undefined method `strip' for nil:NilClass", "exception.backtrace": [ "ee/lib/gitlab/llm/templates/review_merge_request.rb:73:in `block in format_custom_instructions_list'", "ee/lib/gitlab/llm/templates/review_merge_request.rb:71:in `map'", "ee/lib/gitlab/llm/templates/review_merge_request.rb:71:in `format_custom_instructions_list'", "ee/lib/gitlab/llm/templates/review_merge_request.rb:56:in `format_custom_instructions_section'", "ee/lib/gitlab/llm/templates/review_merge_request.rb:25:in `to_prompt_inputs'", "ee/lib/gitlab/llm/ai_gateway/completions/review_merge_request.rb:375:in `prepare_prompt_inputs'", "..." ], "extra.unit_primitive": "review_merge_request" } ``` ### Output of checks This bug happens on GitLab.com ### Possible fixes The issue is in `ee/lib/gitlab/llm/templates/review_merge_request.rb` at line 73: ```ruby "#{instruction[:instructions].strip}\n" ``` When the YAML uses an unexpected schema (e.g., `rules[].check` instead of `instructions`), the `instruction[:instructions]` value is `nil`, causing the `NoMethodError`. Suggested fixes: 1. Add schema validation when parsing the `.gitlab/duo/mr-review-instructions.yaml` file (likely in the code that populates `custom_instructions`) 2. Add nil-safe handling: `instruction[:instructions]&.strip` with appropriate fallback 3. Return a user-friendly error message when validation fails, pointing to documentation ### Patch release information for backports N/A - This is a UX improvement for error handling, not a critical security or data loss issue.
issue