انتقل إلى المحتوى
أمين أبوزيد
درس مخطط لهJNR-056-L03

المخرجات المهيكلة إلى records والتحقق منها

  • الدرس 3 من 7
  • Junior
في هذا الدرس 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.
تفاصيل المخطط المبدئي

عرض عملي

java
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.

التطبيق

طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.

المختبر والتمارين الاختبار

تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.

اكتب للبحث في المستويات والمراحل والوحدات والدروس.