Improve GitLab Duo MR Review error handling for schema formatting
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
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
Steps to reproduce
- Create a
.gitlab/duo/mr-review-instructions.yamlfile with an incorrect schema format, for example: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. - Create a merge request in the project
- Trigger GitLab Duo MR Review
Example Project
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:
- Validate the YAML schema before attempting to process custom instructions
- Provide a clear, user-friendly error message indicating the configuration file format is incorrect
- Point users to documentation showing the correct schema format
Expected schema format:
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
{
"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:
"#{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:
- Add schema validation when parsing the
.gitlab/duo/mr-review-instructions.yamlfile (likely in the code that populatescustom_instructions) - Add nil-safe handling:
instruction[:instructions]&.stripwith appropriate fallback - 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.