المخرج المنظم عبر الموردين
JSON بس عبر الـvendors — 3 أشكال فشل
أنضف اختبار لانضباط الـstructured-output بتاع أي vendor هو تعليمة strict-JSON. المستخدم بيقول صراحة "JSON object بس (من غير نثر، من غير markdown fence)" وبيدّيك الـschema. فيه شكل إجابة واحد مقبول. وفيه طرق كتير تخسّ بيها. بصّ على كل نموذج بيعمل إيه.
الـprompt
Extract the structured data from this paragraph and return ONLY a JSON object (no prose, no markdown fence). Schema: { "company": string, "founded_year": number, "headquarters_city": string, "products": string[] }
Paragraph: "Bayt Coffee, founded in 2019 in Cairo, sells three main products: a house blend, single-origin Ethiopian, and a cold-brew concentrate."
Claude Sonnet 4.5
{ "company": "Bayt Coffee", "founded_year": 2019, "headquarters_city": "Cairo", "products": ["house blend", "single-origin Ethiopian", "cold-brew concentrate"] }
GPT-4o-mini
{ "company": "Bayt Coffee", "founded_year": 2019, "headquarters_city": "Cairo", "products": [ "house blend", "single-origin Ethiopian", "cold-brew concentrate" ] }
Gemini 2.5 Flash
{"company": "Bayt Coffee", "founded_year": 2019, "headquarters_city": "Cairo", "products": ["a house blend", "single
بطاقة المقارنة
اختبار strict-JSON: مين بيرجّع bytes تتـparse؟
Claude Sonnet 4.5
- الـfence بيكسر قاعدة 'no markdown'
- محتاج تنضيف قبل الـparsing
GPT-4o-mini
- النموذج الوحيد اللي التزم بقاعدة الـno-fence
- بيتـparse على طول
Gemini 2.5 Flash
- اتقطع في نص الـstring عند 'single
- حرّف في صياغة المنتج ('a house blend')
اللي ده بيقوله لنا
3 failure modes مختلفة، باينة بالظبط في الـcaptures.
Claude لفّ الـJSON في ```json ... ``` markdown fence مع إن الـprompt قال "no markdown fence". المحتوى جوه الـfence هو JSON صالح، schema-correct، بـtypes صح. بس لو الكود ورا بيعمل JSON.parse(output) ببساطة، هيرمي error بسبب الـ ``` في الأول. ده failure mode بتاع Claude الأشهر في الـstructured-output: الـJSON نفسه صح، بس ملفوف.
GPT-4o-mini رجّع JSON عاري، من غير fence، من غير نثر، parse صالح. على الـprompt ده GPT-4o-mini هو الوحيد فيهم التلاتة اللي طلّع مخرج تقدر تبعته على طول لـJSON.parse. بصّ إن GPT-4o-mini اختار الـ"pretty" multi-line formatting؛ ده تمام للـparser. أسامي المنتجات مطابقة للمصدر.
Gemini 2.5 Flash اتقطع في نص الـstring: "products": ["a house blend", "single — من غير closing quote، من غير closing bracket، من غير closing brace. أياً كان max-output budget بتاع Gemini Flash، الـprompt ده وصله. وأوحش من كده: النص الجزئي ضاف كلمة زيادة ("a house blend" بدل "house blend") ما كانتش في مخرج أي نموذج تاني. يعني Gemini حرّف في الكلمة واتقطع.
للـproduction، الـpatches متوقعة. لـClaude: اقطع json في الأول و في الآخر قبل الـparsing، أو استخدم tool-use mode بتاع Anthropic اللي بيجبر JSON object. لـGPT-4o-mini على المهمة دي: استخدم response_format: { type: "json_object" } بتاع OpenAI والنموذج بيبقى أكتر موثوقية من نسخة الـprompt-only. لـGemini: ما تستخدمش Flash لـstrict-JSON على input أكتر من كام مية حرف — اطلع لـGemini Pro أو استخدم structured-output API mode اللي Google بتشحنه منفصل.
Captured 2026-04-27 من Claude Sonnet 4.5 و GPT-4o-mini و Gemini 2.5 Flash. الـre-runs ممكن تختلف شوية.
التالي: function calling — نفس الفكرة، API surface مختلف، مشاكل parity مشابهة. :::
سجّل الدخول للتقييم