Structured Output Converter in Spring AI
Structured Output Converter in Spring AI Suppose you ask OpenAI: "Provide the major cities of India." Normally, AI returns plain text . India has many major cities such as Mumbai, Delhi, Bengaluru, Hyderabad and Chennai. In Java, you'll get: String response = chatClient.prompt() .user( "Provide major cities of India" ) .call() .content() ; Type: String Problem: It's just text. You have to parse it yourself. AI may change the format every time. Step 2: Structured Output Instead of asking AI for plain text, we ask: "Return the response in a structured format." { "country" : "India" , "cities" : [ "Mumbai" , "Delhi" , "Pune" ] } This is called Structured Output . It means: AI returns JSON instead of plain text. Step 3: POJO (Plain Old Java Object) Now create a Java class (or record) to hold this JSON...