What you will be able to do
- Judge whether a candidate few-shot example adds something no other prompt element already provides
- Pick, between candidates, the one that covers a tool path or query shape the agent has not yet seen demonstrated
- Decide when an output-format example is needed and when an enforced schema makes it redundant
- Write examples that show how to handle an ambiguous request with a clarifying question or a stated default
- Measure what each example contributes by evaluating candidate example sets on the same data
Key concept
Marginal contribution of a few-shot example — What an example adds to agent performance beyond what the instructions, tool descriptions, enforced schemas and other examples already provide. Keep an example only if it teaches something nothing else does and the gain is worth the tokens it costs on every request.
1.Every example is paid for on every request
A few-shot example in a system prompt costs input tokens on every request the agent serves, including the many requests it has nothing to do with. An example that fixes a failure on one query in fifty is still read on the other forty-nine. That makes example selection a budgeting problem: the question is never just whether an example is good, but whether it is worth more than the tokens and attention it takes from everything else in the context.
The attention budget is the other half of the cost. Each extra element competes for the model's focus, so an example that adds nothing new does more than waste tokens: it dilutes the examples that do matter. Include an example only when its gain in performance outweighs both costs.
Marginal contribution is the test that follows. Ask what this example teaches that the instructions, the tool descriptions, any enforced output schema and the other examples do not already teach. Three answers usually justify the cost:
- it demonstrates a tool path or query shape the agent currently gets wrong
- it shows an output structure the agent cannot reliably produce from a description alone
- it shows how to handle an ambiguous input, either by asking a clarifying question or by applying a stated default
If the honest answer is "nothing new, it just reinforces", the example is a candidate for removal, however well written it is.
Checkpoint 1 of 9· Check yourself
A Databricks agent's system prompt is at its token budget with five few-shot examples. Three of them show the same vector-search tool call, each with different user wording. A new candidate example shows a Unity Catalog function tool that the agent often calls with wrong parameters. What is the best move?
Every example costs tokens and attention on every request. The extra vector-search examples teach nothing new, while the new example covers a tool path the agent gets wrong. So a full budget calls for a swap, not for rejecting the newcomer or growing the prompt.
“Overall latency and token consumption are examples of chain performance metrics.”Source: docs.databricks.com
Sources1
2.Untested tool paths beat reinforced ones
The most valuable example demonstrates a path the agent currently mishandles. Picture a support agent with three examples, all of which call lookup_order for a status question. A fourth example that calls lookup_order again, with the user wording the request a little differently, adds almost nothing. The model already generalizes across phrasings from one clear demonstration. An example that walks through the return flow, which no current example touches, covers behavior the agent has never seen demonstrated. Wrong tool choices and repeated or invalid calls tend to cluster on exactly these uncovered paths.
Size is the price of an example, not the test of whether to include it. A multi-step example is longer than a one-line filter, but if it covers a path users hit every week that nothing else demonstrates, it has a higher marginal contribution than a short example that repeats a covered path. Rejecting it for being longer optimizes the wrong variable.
Genie spaces make this concrete. In a Genie space, the few-shot examples are the example SQL queries: each pairs a sample question with the SQL that answers it, and each counts against the space's instruction limit. Genie spaces are now called Genie Agents in the documentation. Suppose a space holds three examples that are all simple single-table filters returning the same output shape, and a candidate shows a multi-step aggregation with a reused calculation the finance team asks for weekly. The justified choice is to add the aggregation example and drop one of the redundant filters. Keep at least one filter example, though, because that shape is still common and dropping all of them removes its coverage completely.
| Candidate | What it adds | Decision under a tight budget |
|---|---|---|
Another lookup_order call with different wording | Nothing beyond the examples already showing that path | Exclude; paraphrase adds cost, not coverage |
| First example of a tool path the agent gets wrong | Behavior no other prompt element demonstrates | Include; swap out a redundant example if needed |
| Longer multi-step example of a frequent, uncovered query | A query shape the agent has not seen | Include; token size is the price, not the criterion |
| Uncovered example rewritten to resemble existing ones | Nothing; the rewrite destroys its value | Never rewrite toward redundancy |
Checkpoint 2 of 9· Match them up
Match each candidate few-shot example to the decision that fits it when the token budget is tight.
Tap a term, then the definition that fits it.
Each example is judged on its marginal contribution. Paraphrases of a covered path add nothing. Examples of uncovered paths matter most, because that is where wrong or invalid tool calls happen, even when those examples are long. Keep at least one example of each shape that is still common, so that shape stays covered.
“Compared to a hard-coded chain, you must guard against repeated or invalid tool calls.”Source: docs.databricks.com
Checkpoint 3 of 9· Exam question
A context engineer is curating few-shot examples for a Genie space under a strict token budget. The candidate pool already has three examples that each demonstrate a straightforward single-table filter query returning the same output shape. A fourth candidate demonstrates a multi-step aggregation with a re-used calculation the finance team asks about weekly. Which action best reflects marginal-contribution reasoning under the budget?
Correct answer: A — Include the fourth example and drop one of the redundant single-table filter examples
Checkpoint 4 of 9· Exam question
A context engineer is deciding between two candidate few-shot examples to add to a nearly full token budget, and only one can be included. Candidate X demonstrates a tool call path the agent has never exercised in any existing example. Candidate Y demonstrates a tool call path already shown clearly in two existing examples, but with slightly different wording in the user request. Which candidate has the higher marginal contribution to agent performance, and why?
Correct answer: B — Candidate X, because it is the only one of the two that covers a tool path the agent has not yet seen demonstrated
3.Examples that demonstrate output structure
When a downstream parser needs strict JSON and the agent sometimes drifts into free text or a slightly different structure, the most direct fix through example selection is to add one example that pairs a representative input with output in the exact required structure. A schema described in prose tells the model what is wanted. An example shows it, and models copy demonstrated structure much more reliably than they follow a description of it.
Two tempting alternatives work worse. Examples of malformed output labeled "wrong" still put the malformed pattern in front of the model, which tends to imitate what it sees. Pulling in more retrieved examples without checking their output format can add more inconsistent structures, which makes the drift worse. Removing every example so the base model falls back on its default formatting also fails, because the default is exactly what is drifting.
Enforcement changes the calculation. With Structured outputs for sub-agent results, a schema passed through response_format constrains generation itself, so an example whose only job was to show the shape becomes redundant. Keep a structured example only if it teaches something beyond shape, such as how to fill a field correctly or which tool path produced the values.
Checkpoint 5 of 9· Check yourself
Your team now passes a strict JSON schema through response_format on every chat request to a ticket-triage agent. The prompt still carries three structured examples. Two exist only to show the JSON shape. The third shows how to fill the priority field correctly when the ticket text is vague. Under a tight token budget, what should happen to these examples?
An enforced schema already guarantees the JSON shape, so the two examples that only show the format are now redundant and still cost tokens on every request. The priority example teaches something the schema does not: how to fill a field correctly. That earns it a place. Examples labeled "wrong" still show the malformed pattern, and the model tends to imitate what it sees.
“You can choose to generate text, unstructured JSON objects, and JSON objects that adhere to a specific JSON schema.”Source: docs.databricks.com
Checkpoint 6 of 9· Exam question
An agent must return responses as strict JSON matching a fixed schema so a downstream pipeline can parse them without error. During evaluation, the agent occasionally returns valid but inconsistently structured free text instead of the required schema. None of the current few-shot examples show the expected output format explicitly. What is the most direct fix using few-shot example selection?
Correct answer: B — Add a few-shot example that shows a representative input paired with output in the exact required JSON structure
Sources4
4.Examples for ambiguous inputs
Instructions are weak at teaching an agent how to handle ambiguity. A rule such as "ask when the request is unclear" leaves the model to decide what counts as unclear, and in practice it guesses. One example does better: "show me last quarter's numbers" answered by asking whether the user means revenue or bookings, or answered with a stated default ("Using fiscal Q3 revenue; tell me if you meant bookings"). Such an example shows when to stop and ask, what a good question looks like, and how to say which default was applied.
The same pattern covers recoverable tool failures. When a lookup returns an invalid identifier, an example in which the agent asks the user for the correct ID, instead of inventing one or retrying blindly, demonstrates a behavior that most other examples, which all succeed on the first try, never show. It is high-value because it is rare.
Ambiguity examples must agree with each other. If one example resolves "last quarter" as calendar Q3 and another as fiscal Q3, the agent learns that either is acceptable, and its answers become inconsistent. Keep one convention, keep one example of it, and drop the other.
Checkpoint 7 of 9· Check yourself
Which prompt change adds the most for a help-desk agent whose prompt already has one example resolving "last quarter" as fiscal Q3 and three examples where lookup_order succeeds on the first call?
None of the current examples shows a recoverable tool failure, because they all succeed on the first try. An example of asking for the correct ID is valuable precisely because that behavior is rare. A calendar Q3 example would conflict with the fiscal Q3 convention and make answers inconsistent. A reworded success adds nothing new. A bare "ask when unclear" rule leaves the model to guess what counts as unclear.
“If that tool responds with "invalid order number," the agent can retry or prompt the user for the correct ID”Source: docs.databricks.com
5.Measuring what each example contributes
Reasoning about coverage tells you which examples are likely to help. Measurement confirms it. The method is ablation: build candidate example sets, such as the current set, the set plus the candidate, and the set with one redundant example removed, then run each one against the same evaluation data. Using Controlled comparison with mlflow.genai.evaluate(), the only variable that changes between runs is the example set, so any difference in quality or token count can be traced to it.
results = mlflow.genai.evaluate(
data=[
{"inputs": {"question": "What is MLflow?"}},
{"inputs": {"question": "How do I get started?"}}
],
predict_fn=my_chatbot_app,
scorers=[RelevanceToQuery(), Safety()]
)The evaluation data decides what the ablation can see. If it contains only the common paths, it cannot reward an example for covering a rare one, and redundant examples will look as good as useful ones. Include the uncovered tool paths, the strict-format cases and the ambiguous requests the candidates are meant to fix. Then read the per-case results next to total_input_token_count. An example that improves no case while adding tokens to every request has a measured marginal contribution below zero.
Checkpoint 8 of 9· Fill the gap
You run one ablation per candidate example set. Each run uses the same data and scorers, and only the app's prompt changes. Which parameter takes the app version under test?
results = mlflow.genai.evaluate(
data=[
{"inputs": {"question": "What is MLflow?"}},
{"inputs": {"question": "How do I get started?"}}
],
? =my_chatbot_app,
scorers=[RelevanceToQuery(), Safety()]
)The app goes in predict_fn. For each example set, you pass a version of the app that carries that set and keep data and scorers the same. Any change in quality or token count then comes from the example set alone.
Source: docs.databricks.comCheckpoint 9 of 9· Check yourself
In an ablation for a support agent, every evaluation case is a lookup_order status question. Adding a return-flow example leaves every score unchanged and raises total_input_token_count. What is the right next step?
An ablation can only reward coverage of paths that appear in its evaluation data. With only status questions in the data, the return-flow example has nothing to improve. Add the uncovered cases first. Only then does a flat result show that the example adds nothing.
“Test edge cases: Include challenging examples in your evaluation dataset.”Source: docs.databricks.com
Sources
(7)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.https://docs.databricks.com/aws/en/agents/tutorials/ai-cookbook/evaluate-assess-performanceOfficial docs
“Overall latency and token consumption are examples of chain performance metrics.”
↩︎ Every example is paid for on every request“Overall latency and token consumption are examples of chain performance metrics.”
↩︎ Exam trap 1 - 2.
“Example SQL queries help Genie generate the correct SQL to answer common user questions.”
↩︎ Untested tool paths beat reinforced ones“Instructions (100 per agent): Each example SQL query, each SQL function, and the entire General instructions text block each count as one instruction.”
↩︎ Untested tool paths beat reinforced ones“it's important to make the guidance free from conflicting or ambiguous information to minimize the risk of undesirable responses.”
↩︎ Examples for ambiguous inputs“Example SQL queries help Genie generate the correct SQL to answer common user questions.”
↩︎ Exam trap 3 - 3.
“Compared to a hard-coded chain, you must guard against repeated or invalid tool calls.”
↩︎ Untested tool paths beat reinforced ones“the agent can retry or prompt the user for the correct ID, continuing until it can provide a final answer.”
↩︎ Examples for ambiguous inputs“Compared to a hard-coded chain, you must guard against repeated or invalid tool calls.”
↩︎ Exam trap 2“If that tool responds with "invalid order number," the agent can retry or prompt the user for the correct ID”
↩︎ Checkpoint - 4.
“Structured outputs on Databricks let you generate responses in a defined JSON format as part of your AI application workflows.”
↩︎ Examples that demonstrate output structure“Structured outputs on Databricks let you generate responses in a defined JSON format as part of your AI application workflows.”
↩︎ Exam trap 4“You can choose to generate text, unstructured JSON objects, and JSON objects that adhere to a specific JSON schema.”
↩︎ Checkpoint - 5.https://docs.databricks.com/aws/en/mlflow3/genai/prompt-version-mgmt/prompt-registry/evaluate-promptsOfficial docs
“Use consistent datasets: Evaluate all versions against the same data for fair comparison.”
↩︎ Measuring what each example contributes“Test edge cases: Include challenging examples in your evaluation dataset.”
↩︎ Checkpoint - 6.https://docs.databricks.com/aws/en/agents/tutorials/ai-cookbook/evaluate-define-qualityOfficial docs
“The set should include difficult and diverse cases to effectively test the model's capabilities.”
↩︎ Measuring what each example contributes
Also cited
“Methods for optimizing trade-offs between quality, cost, and latency.”
↩︎ Key concept