{"record":{"id":"1e43ea0cbd42c957","repo":"conductor-oss/conductor","slug":"output-does-not-confirm-to-the-schema-errors-s","errorCode":null,"errorMessage":"Output does not Confirm to the schema.  errors: %s","messagePattern":"Output does not Confirm to the schema\\.  errors: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"ai/src/main/java/org/conductoross/conductor/ai/LLMHelper.java","lineNumber":300,"sourceCode":"            }\n            default -> llmResponse.setResult(result.toString());\n        }\n    }\n\n    @SneakyThrows\n    private Object tryToConvertToJSON(String responseText, ChatCompletion chatCompletion) {\n        try {\n            responseText = responseText.trim();\n            if (responseText.startsWith(\"```json\")) {\n                responseText = responseText.substring(\"```json\".length());\n                responseText =\n                        responseText.substring(0, responseText.length() - \"```\".length() - 1);\n            }\n            Map<String, Object> map = objectMapper.readValue(responseText, MAP_OF_STRING_TO_OBJ);\n            if (chatCompletion.getOutputSchema() != null) {\n                String error = validateJsonSchema(chatCompletion.getInputSchema(), map);\n                if (error != null) {\n                    throw new RuntimeException(\n                            String.format(\n                                    \"Output does not confirm to the schema.  errors: %s\", error));\n                }\n            }\n            // llmResponse.setResult(map);\n            return map;\n\n        } catch (JsonProcessingException e) {\n            if (chatCompletion.isJsonOutput()) {\n                log.error(\n                        \"error converting to json, response: {}, error: {}\",\n                        responseText,\n                        e.getMessage(),\n                        e);\n                Map<String, Object> outputErrors =\n                        Map.of(\"error\", e.getMessage(), \"response\", responseText);\n                throw new RuntimeException(objectMapper.writeValueAsString(outputErrors));\n            }","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/conductor-oss/conductor/blob/cf7c3e4a8adfb158be778ab1ec525323c363cd3a/ai/src/main/java/org/conductoross/conductor/ai/LLMHelper.java#L282-L318","documentation":"Thrown by LLMHelper.tryToConvertToJSON() when the LLM response text was successfully parsed as JSON but failed JSON schema validation against the configured output schema. The message includes the specific validation error(s). Note: the message says 'confirm' but means 'conform' — a typo in the source.","triggerScenarios":"The LLM returns text that is valid JSON (a Map) but does not match the outputSchema defined on the ChatCompletion. The schema validation runs via validateJsonSchema() using the networknt JSON schema validator, and validation messages are collected and formatted into the error string.","commonSituations":"The LLM omitted required fields or added extra fields not allowed by additionalProperties:false. The LLM returned a different structure than expected (e.g. an array where an object was expected). The schema is too strict or the prompt doesn't adequately describe the expected output format. Model temperature is too high causing inconsistent output.","solutions":["Review the validation error details in the exception message to identify which fields failed","Improve the prompt to clearly specify the expected JSON structure, possibly include an example","Relax the schema if appropriate (e.g. allow additional properties, make fields optional)","Lower the model temperature or add explicit formatting instructions in the system prompt"],"exampleFix":"// before: schema requires {\"name\": string, \"age\": int}\n// LLM returns: {\"name\": \"Alice\"}  // missing required 'age'\n// after: improve prompt to say 'You must include both name and age fields'","handlingStrategy":"validation","validationCode":"// Before running the LLM, validate that the schema is well-formed\nif (chatCompletion.getOutputSchema() != null) {\n    String schemaJson = objectMapper.writeValueAsString(chatCompletion.getOutputSchema().getData());\n    // Optionally pre-validate with an external JSON Schema validator\n    // to catch schema issues before the LLM call\n}","typeGuard":null,"tryCatchPattern":"try {\n    LLMResponse response = llmHelper.chatComplete(task, llm, chatCompletion, location, logger);\n} catch (RuntimeException e) {\n    if (e.getMessage().contains(\"Output does not confirm to the schema\")) {\n        // Schema validation failed — the LLM output didn't match\n        // Consider retrying with a more specific prompt or relaxing the schema\n        log.warn(\"Schema validation failed for LLM output: {}\", e.getMessage());\n        taskResult.setStatus(TaskResult.Status.FAILED);\n    } else {\n        throw e;\n    }\n}","preventionTips":["Design schemas to be permissive enough for natural LLM variation","Test schemas with sample outputs before deploying to production","Include the expected JSON structure in the system prompt to guide the model","Consider setting additionalProperties:true if strict matching isn't required"],"tags":["ai","llm","json-schema","validation"],"backgroundTag":null,"analyzedSha":"cf7c3e4a8adfb158be778ab1ec525323c363cd3a","analyzedAt":"2026-08-14T03:33:19.897Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}