المخرجات المهيكلة إلى records والتحقق منها
في هذا الدرس 4 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
get typed data instead of free text.
الموضوعات المخطط لها
- Parsing free text with string tricks breaks easily. Ask for structured output instead.
- Spring AI can map the reply into a Java record with
.entity(MyRecord.class); it adds format instructions to the prompt. - The model may still return wrong or missing values. Treat the result as untrusted input.
- Validate with Bean Validation (
@NotBlank,@Size) before use. - On failure, return a clear error or a safe fallback; never pass bad output further.
تفاصيل المخطط المبدئي
عرض عملي
record Description(@NotBlank String title, @Size(max = 300) String text) {}
Description d = chatClient.prompt().user(...).call().entity(Description.class);
validator.validate(d); // reject if violationsاختبر فهمك
Why validate model output?
أظهر الإجابة
It is not guaranteed to follow your format or rules.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.