CCDV-F Prep unofficial
← All skills

Prompt and Context Engineering

Grounding and Source Citation

Exam objective: Constructing a request that grounds answers in the supplied documents, cites their source, and returns 'not found' when the documents do not contain the answer. This includes deciding, based on corpus size, cost, and freshness, whether to supply the full document set in context or retrieve only the relevant passages.

What the exam tests

Whether you can build a request that answers only from supplied documents, shows where each claim came from, and says "not found" when the documents lack the answer. It also tests the architecture choice behind it: put the whole corpus in context, or retrieve only relevant passages, based on corpus size, cost and freshness.

Key rules

Grounding in the prompt

  • Tell Claude to use only the provided documents, not general knowledge, and give it explicit permission to say the answer is not there.
  • With long inputs (20k+ tokens), put documents at the top and the query after them. Wrap each in <document> tags with source metadata.
  • Ask for relevant word-for-word quotes first, then answer from those quotes.
  • These reduce hallucinations; they do not eliminate them. Validate high-stakes answers.

Citations

  • Set citations: {"enabled": true} on every document in the request (all or none).
  • The API returns cited_text plus a location. It does not count toward output tokens, and the pointers are guaranteed to be valid.
  • Source type decides granularity and location:
SourceCitable unitLocation
Plain textsentencecharacter indices (0-indexed)
PDFsentencepage numbers (1-indexed)
Custom contentyour blocksblock indices (0-indexed)
search_resultyour blockssource, title, block indices
  • title and context reach the model but are never cited.
  • RAG chunks: use search_result blocks (in a tool result or a user message). They require source, title and content, and citations are off unless enabled.
{"role": "user", "content": [
  {"type": "document",
   "source": {"type": "text", "media_type": "text/plain", "data": "..."},
   "title": "Leave policy", "citations": {"enabled": true},
   "cache_control": {"type": "ephemeral"}},
  {"type": "text", "text": "Answer only from the policy. If it does not cover the question, say it was not found. How many days of study leave do I get?"}
]}

Full context or retrieval

  • Small and stable corpus: include all of it and cache it. Anthropic's Contextual Retrieval article suggests this below roughly 200,000 tokens.
  • Larger than the window, or changing often: retrieve at request time.
  • Fitting is not the only limit: accuracy and recall degrade as context grows, and cached tokens still occupy the window.
  • Better retrieval: combine embeddings with BM25 (exact terms), prepend chunk-specific context before indexing, then rerank.
  • Anthropic has no embedding model of its own; Voyage AI is one provider.
  • The Files API avoids re-uploading, but referenced content is still billed as input tokens. Files cannot be modified, and file IDs must never come from untrusted users.

Traps

  • Citations plus output_config.format returns a 400. For cited fields, request field: value lines and parse them; check each has a citation.
  • A "return only JSON" prompt succeeds but may produce few or no citations.
  • Scanned PDFs without extractable text can be read but not cited. Images are never cited.
  • In a tool_result, if one block is a search_result, all must be.
  • An empty search should return a text block such as "No results found.", not raise or pad with irrelevant hits.
  • Asking for quotes in the prompt is not the same as citations: generated quotes can be wrong.

Decide quickly

SituationChoiceWhy
Stable manual that fits easily, many queriesFull document + prompt cachingSimple, nothing gets missed, cheap reuse
Millions of tokens or hourly updatesSearch tool returning search_result blocksCurrent, relevant passages with attribution
Transcript or bullet list needing exact unitsCustom content documentNo automatic chunking
Exact IDs or error codes missedAdd BM25 to embeddingsLexical match
Chunks ambiguous out of contextContextual RetrievalRestores lost context
Cited data needed as fieldsLine-oriented text, parsed in codeStructured outputs are incompatible
Answer absent from documentsExplicit "not found" instructionRemoves pressure to invent

Sources