
إنك تكتب «اذكر المصادر» في الـ prompt مش grounding: استخدم الـ Citations في Claude
- كاتب موثّق
- Claude API
محتويات المقال
الفكرة الغلط الشائعة
Claude بيمشي على تعليمات الـ formatting كويس، فكل إجابة بترجع بـ references مترتبة وثابتة الشكل. الـ spot checks بتعدّي: أغلب الـ citations اللي من الـ prompt صح، فالغلط بيبقى نادر وسهل يفوتك. الـ guide بتاع Anthropic نفسه لتقليل الـ بينصح إنك تطلب من Claude يقتبس ويذكر المصدر. والـ reference اللي فيه رقم سكشن وعلامات تنصيص شكله كأن سيستم اتأكد منه.
اللي بيحصل فعلًا
الـ citation اللي من الـ prompt مجرد output زيادة
الـ Citations feature بترجّع pointers، مش كلام
document blocks ومعاها "citations": {"enabled": true}، والـ API هو اللي بيشيل الحسابات:
المستندات بتتقسم chunks الـ plain text والـ PDFs بيتقسموا لجمل؛ والـ custom content documents بتفضل بالـ blocks اللي انت بعتها من غير أي تقسيم زيادة. والـ chunk هو أصغر حاجة Claude يقدر يستشهد بيها. Claude بيجاوب على شكل blocks الـ response بيبقى كذا textblock. والـ block اللي فيه claim من مستنداتك بيبقى معاه list اسمهاcitations.الـ API بيحط الأماكن بالظبط كل citation فيها cited_textوdocument_indexوdocument_titleومكان: range حروف للـ plain text، وrange صفحات للـ PDFs، وrange blocks للـ custom content.
{ "type": "text", "text": "the grass is green", "citations": [{ "type": "char_location", "cited_text": "The grass is green. ", "document_index": 0, "document_title": "Example Document", "start_char_index": 0, "end_char_index": 20 }]}cited_text بنفسه، الـ docs بتقول إنها "are guaranteed to contain valid pointers to the provided documents". وكمان cited_text مش بيتحسب من الـ output tokens، فلو كنت بتطلب من Claude ينقل الاقتباسات، ممكن تدفع أقل.
الضمان ده مش بيغطي إيه
نعيد كتابة الـ assistant
import anthropicclient = anthropic.Anthropic()reply = client.messages.create( model="claude-opus-5-5", max_tokens=2048, system="Answer from the handbook. Cite every claim as [Handbook §x.y].", messages=[{"role": "user", "content": f"<handbook>{HANDBOOK}</handbook>\n{QUESTION}"}],)answer = next(b.text for b in reply.content if b.type == "text")print(answer) # "[Handbook §4.2]" is text Claude wrote; nothing checked itimport anthropicclient = anthropic.Anthropic()reply = client.messages.create( model="claude-opus-5-5", max_tokens=2048, messages=[{"role": "user", "content": [ {"type": "document", "title": "Employee Handbook 2026", "source": {"type": "text", "media_type": "text/plain", "data": HANDBOOK}, "citations": {"enabled": True}}, {"type": "text", "text": QUESTION}, ]}],)for block in reply.content: if block.type == "text": quotes = [c.cited_text for c in block.citations or []] print(repr(block.text), "<-", quotes or "no citation")cited_text، منسوخ من المستند | ||
document_index ومعاه range حروف أو صفحات أو blocks | ||
تطبقها إزاي في مشروعك
دوّر على الـ citations اللي في الـ prompts دوّر في الـ prompts على "cite" و"source" و"quote"، وفي الكود على أي regex بيطلّع references من الإجابات. ابعت المصادر كـ documents عليها citations ابعت كل مصدر كـ documentblock والـcitationsمتفعّلة. والموضوع يا كله يا بلاش: كل المستندات في الـ request لازم يبقى ليها نفس الإعداد.اعرض من الـ citations array اعرض cited_textواعمل link للصفحة أو الـ range، بدل ما تثق في references مكتوبة جوه الإجابة.اعتبر الـ claims اللي ملهاش citation مش مدعومة الجملة اللي فيها معلومة ومن غير citation دي إشارة: علّم عليها، أو خبّيها، أو ابعتها للمراجعة. اتأكد من الـ relevance في الـ evals بتاعتك على عينة من الإجابات، اتأكد إن كل cited_textبيدعم الجملة بتاعته فعلًا. الـ pointer السليم ممكن برضه يشاور على الجزء الغلط.
الخلاصة
الـ citation اللي بتطلبها في الـ prompt نص متولّد؛ ومحدش بيقارنها بمستنداتك. الـ Citations feature بترجّع أماكن structured والـ pointers بتاعتها مضمونة، ومعاها cited_textاللي مش بيتحسب من الـ output tokens.الـ pointer السليم مش دليل: إن الجزء يدعم الـ claim لسه حكم Claude. فيه text blocks من غير citations، فقرر في الكود هتعمل إيه في الـ claims اللي ملهاش citation. الـ citations والـ structured outputs مبيتجمعوش؛ استخدم سطر لكل field لو محتاج الاتنين.
التعليقات (0)