Bug description: When using Spring AI with a JSON-formatted prompt, an exception org.stringtemplate.v4.compiler.STException: null is thrown,16:12: '"object"' came as a complete surprise to me . This happens when trying to generate text using a structured prompt with JSON input.

Environment:

Spring AI version: 1.0.0-M4

Java version: 21 Vector Store : yes

Other relevant dependencies: spring-ai-openai-spring-boot-starter

Steps to reproduce:

Use Spring AI to generate text with a structured JSON prompt.

Ensure the JSON is properly formatted.

Run the request and observe the error.

Expected behavior: Spring AI should correctly process the JSON prompt and return the expected response without throwing an STException.

Minimal Complete Reproducible example:

String prompt = """ You are an assistant that takes a patient's summarized clinical data and associates each active condition with any relevant recent encounters and current medications.

Steps to follow: 1. Review the patient's demographics, conditions, recent encounters, and current medications. 2. For each condition in 'conditions': - Determine which of the 'recent_encounters' are relevant. An encounter is relevant if: - The 'reason_display' or 'type_display' of the encounter mentions or is closely related to the condition. - Consider synonyms or partial matches. For example, for "Childhood asthma (disorder)", any encounter mentioning "asthma" or "asthma follow-up" is relevant. - Determine which of the 'current_medications' are relevant. A medication is relevant if: - The medication 'name' or 'instructions' are clearly related to managing that condition. For example, inhalers or corticosteroids for asthma, topical creams for dermatitis. - Consider partial matches. For "Atopic dermatitis (disorder)", a medication used for allergic conditions or skin inflammations could be relevant. 3. Ignore patient demographics for relevance determination; they are just context. 4. Return the final output strictly as a JSON object following the schema . Json outpout { "type": "object", "properties": { "bundles": { "type": "array", "items": { "type": "object", "properties": { "condition": { "type": "object", "properties": { "clinicalStatus": { "type": "string" }, "code": { "type": "string" }, "display": { "type": "string" } } }, "encounters": { "type": "array", "items": { "type": "object", "properties": { "date": { "type": "string" }, "reasonDisplay": { "type": "string" }, "typeDisplay": { "type": "string" } } } }, "medications": { "type": "array", "items": { "type": "object", "properties": { "instructions": { "type": "string" }, "name": { "type": "string" }, "startDate": { "type": "string" } } } } } } } } }

Do not include extra commentary outside the JSON.

Patient Data: givenName = Almeta56 familyName = Buckridge80 birthDate = 2010-12-31 gender = female conditions = Atopic dermatitis (disorder) (24079001), Childhood asthma (disorder) (233678006) recentEncounters = 2024-01-26T01:38:45-08:00 - Well child visit (procedure), 2024-02-09T01:38:45-08:00 - Encounter for check up (procedure), 2024-10-05T21:38:45-07:00 - Asthma follow-up (regime/therapy) currentMedications = Loratadine 5 MG Chewable Tablet (Instructions: Take as needed.), NDA020800 0.3 ML Epinephrine 1 MG/ML Auto-Injector (Instructions: Take as needed.), 120 ACTUAT fluticasone propionate 0.044 MG/ACTUAT Metered Dose Inhaler Flovent (Instructions: Take as needed.), albuterol 0.417 MG/ML Inhalation Solution (Instructions: Take as needed.)

""";

// Call Spring AI with this prompt ChatClient chatClient = builder.build(); BeanOutputConverter beanOutputConverter = new BeanOutputConverter<>(ConditionBundles.class); //String format = beanOutputConverter.getFormat();

    Prompt prompt = new PromptTemplate(CONDITION_BUNDLE_PROMPT, Map.of("format", format,"patientData",patientInfoJson)).create();
    System.out.println("CONDITION_BUNDLE_PROMPT : " + prompt.getContents());

    ChatResponse response = chatClient.prompt(prompt)
            .call()
            .chatResponse();
    //return parseResult(response);
    ConditionBundles conditionBundles = beanOutputConverter.convert(response.getResult().getOutput().getContent());
    return conditionBundles;

Additional context:

Removing the $schema field from JSON does not solve the issue.

Ensuring JSON does not have extra Markdown formatting (e.g., triple backticks) does not resolve the error.

The issue seems related to how Spring AI parses structured prompts internally.

Would appreciate any insights or workarounds. Thanks!