A Spring Boot REST API application that analyzes incident descriptions using Gemini 2.5 Fast LLM and returns structured JSON responses.
The application implements a clear pipeline with separate stages:
- Input parsing - Validates and cleans the incident description
- Context loading - Loads system description and past incidents
- Prompt construction - Builds the LLM prompt with context
- LLM call - Calls Gemini 2.5 Fast API
- Output validation - Validates response structure and content
- Retry/recovery logic - Retries up to 2 times on failure
POST /api/analyze
{
"incident": "string"
}{
"category": "string",
"summary": "string",
"severity": "low|medium|high",
"hypotheses": [
{
"title": "string",
"reasoning": "string",
"nextSteps": ["string", "string"]
}
]
}- Java 17+
- Maven 3.6+
- Gemini API Key
Set the following environment variable:
# On Windows
set GEMINI_API_KEY=your_gemini_api_key_here
# On Linux/Mac
export GEMINI_API_KEY=your_gemini_api_key_hereThe application uses application.yml for configuration:
server:
port: 8080
gemini:
api:
key: ${GEMINI_API_KEY}
logging:
level:
org.elmez.iaj: DEBUG- Clone the repository
- Set the GEMINI_API_KEY environment variable
- Run the application:
mvn spring-boot:run
- The application will start on port 8080
curl -X POST http://localhost:8080/analyze -H "Content-Type: application/json" -d '{ "incident": "Payment service is experiencing timeouts and users cannot complete transactions" }'Invoke-RestMethod -Uri "http://localhost:8080/analyze" -Method Post -ContentType "application/json" -Body '{ "incident": "Payment service is experiencing timeouts and users cannot complete transactions" }'http://localhost:8080/api/models
src/main/java/org/elmez/iaj/
├── Main.java # Spring Boot main class
├── controller/
│ └── IncidentController.java # REST API controller
├── service/
│ ├── IncidentAnalysisService.java # Main orchestrator service
│ └── GeminiClient.java # Gemini API client
├── model/
│ ├── IncidentRequest.java # Request DTO
│ ├── IncidentResponse.java # Response DTO
│ └── Hypothesis.java # Hypothesis model
├── validation/
│ └── ResponseValidator.java # Response validation
├── prompt/
│ └── PromptBuilder.java # LLM prompt construction
└── context/
└── SystemContext.java # System knowledge and past incidents
- Structured Pipeline: Clear separation of concerns with explicit stages
- Response Validation: Comprehensive JSON structure validation with detailed error messages
- Case-Insensitive Enum Handling: Supports both lowercase and uppercase severity values
- Error Handling: Proper HTTP status codes and descriptive error responses
- Logging: Debug-level logging for troubleshooting and monitoring
- Configuration: Environment-based configuration with YAML support
- Input Validation: Bean validation for request parameters
Run the unit tests:
mvn test- Spring Boot 3.2.5
- Spring Web (REST API)
- Spring Validation (request validation)
- Jackson (JSON processing)
- Lombok (reduces boilerplate)
- Google Generative AI SDK (v1.51.0)