Skip to content

Commit 461f3e1

Browse files
thomas-vilteclaude
andcommitted
fix: ensure PR summarizer uses template for JSON format instructions
## Problem PR summarizer was passing raw PR content directly to Gemini without wrapping it in the prompt template, causing the AI to echo back the PR metadata as JSON instead of generating a proper summary. This resulted in error: "422 Validation Failed - missing_field: title" ## Solution - Modified GeneratePRSummary to call generatePRPrompt() to wrap PR content in the template with JSON format instructions - Added validation to ensure title is not empty before returning - Added detailed error message showing AI response when title is missing ## Impact - PR summarization now works correctly - AI generates proper JSON with title, body, and labels - Better error messages for debugging 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 58ea791 commit 461f3e1

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

internal/infrastructure/ai/gemini/pull_requests_summarizer_service.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@ func NewGeminiPRSummarizer(ctx context.Context, cfg *config.Config, trans *i18n.
5252
}, nil
5353
}
5454

55-
func (gps *GeminiPRSummarizer) GeneratePRSummary(ctx context.Context, prompt string) (models.PRSummary, error) {
55+
func (gps *GeminiPRSummarizer) GeneratePRSummary(ctx context.Context, prContent string) (models.PRSummary, error) {
5656
modelName := string(gps.config.AIConfig.Models[config.AIGemini])
5757

58+
// Envolver el contenido del PR en el template con instrucciones de formato JSON
59+
prompt := gps.generatePRPrompt(prContent)
60+
5861
genConfig := &genai.GenerateContentConfig{
5962
Temperature: float32Ptr(0.3),
6063
MaxOutputTokens: int32(10000),
@@ -82,6 +85,16 @@ func (gps *GeminiPRSummarizer) GeneratePRSummary(ctx context.Context, prompt str
8285
return models.PRSummary{}, fmt.Errorf("error al parsear JSON de PR: %w", err)
8386
}
8487

88+
// Validar que el título no esté vacío
89+
if strings.TrimSpace(jsonSummary.Title) == "" {
90+
respLen := len(responseText)
91+
preview := responseText
92+
if respLen > 500 {
93+
preview = responseText[:500] + "..."
94+
}
95+
return models.PRSummary{}, fmt.Errorf("la IA no generó un título para el PR. Respuesta (longitud: %d): %s", respLen, preview)
96+
}
97+
8598
return models.PRSummary{
8699
Title: jsonSummary.Title,
87100
Body: jsonSummary.Body,

0 commit comments

Comments
 (0)