diff --git a/core/src/commonMain/kotlin/com/xebia/functional/xef/llm/models/functions/JsonSchema.kt b/core/src/commonMain/kotlin/com/xebia/functional/xef/llm/models/functions/JsonSchema.kt index e7211c2aa..6fd44efd1 100644 --- a/core/src/commonMain/kotlin/com/xebia/functional/xef/llm/models/functions/JsonSchema.kt +++ b/core/src/commonMain/kotlin/com/xebia/functional/xef/llm/models/functions/JsonSchema.kt @@ -327,15 +327,21 @@ private fun JsonObjectBuilder.applyJsonSchemaDefaults( if (descriptor.kind == SerialKind.ENUM) { this["enum"] = descriptor.elementNames descriptor.elementNames - .mapIndexed { index, name -> - "$name (${descriptor.getElementAnnotations(index).lastOfInstance()?.value})" + .mapIndexedNotNull { index, name -> + val enumDescription = + descriptor.getElementAnnotations(index).lastOfInstance()?.value + if (enumDescription != null) { + "$name ($enumDescription)" + } else { + null + } } .joinToString("\n - ") } else null if (annotations.isNotEmpty()) { val description = annotations.filterIsInstance().firstOrNull()?.value - if (additionalEnumDescription != null) { + if (!additionalEnumDescription.isNullOrEmpty()) { this["description"] = "$description\n - $additionalEnumDescription" } else { this["description"] = description