CertSafari
    Databricks Certified Generative AI Engineer Associate· Lessons

    Domain 1 · Lesson 3/56

    Selecting chain components from the input you have and the output you need

    Select chain components for a desired model input and output

    16 min read
    2.33% of exam
    8 sources
    Published 22 Oct 2026
    Docs as of 17 Oct 2026

    What you will be able to do

    • Name the standard components of a chain (query understanding, retriever, prompt template, LLM, output parser) and place each where it belongs in the input-to-output flow
    • Choose semantic, keyword, hybrid or structured (Unity Catalog function or Genie) retrieval based on what the query looks like and where the answer lives
    • Pick a schema-constrained output component when a downstream system, not a person, reads the result
    • Decide whether a fixed chain fits, or whether the steps depend on intermediate results

    Key concept

    Chain — An ordered pipeline of components that takes a raw user input and turns it into the output the application needs. You pick each component by asking what the step before it hands over and what the step after it expects to receive.

    1.The chain as an input-to-output pipeline

    A chain exists because a model call alone rarely matches both ends of the problem. On one end the user types a question. On the other, a person or a downstream system needs an answer grounded in your data and shaped the way it expects. Every component in between closes part of that gap, and its position follows from what it consumes and what it produces.

    At inference time, the standard RAG chain runs these components in order:

    1. Query understanding (optional) turns the raw user text into a retrieval query, for example by rewriting it or extracting keywords.
    2. Retriever embeds the retrieval query with the same embedding model used on the document chunks, ranks chunks by similarity, and returns the top results.
    3. Prompt template (prompt augmentation) combines the user's query with the retrieved context and instructions.
    4. LLM generates a response grounded in that context.
    5. Output parser (post-processing, optional) applies business logic, adds citations, or enforces a format on the raw response.
    What each component consumes and produces
    ComponentTakes inHands on
    Query understandingRaw user query, possibly with conversation historyA retrieval query, plus any extracted filters or keywords
    RetrieverRetrieval queryTop-k relevant chunks
    Prompt templateUser query and retrieved chunksAn augmented prompt with instructions
    LLMAugmented promptGenerated response
    Output parser / post-processingRaw LLM responseRefined text, citations, or a validated structure

    Order is fixed by the data flow, not by preference. Grounding context has to exist before the LLM sees the prompt, so when a chain needs product documentation chunks from a Databricks AI Search index (formerly Vector Search), the retriever goes immediately before the prompt template and LLM, and it returns only the top-k chunks. A parser cannot supply context because it runs after generation. Pasting the entire documentation set into the system prompt skips retrieval altogether, and the point of the retriever is to pick the few chunks that matter. How many chunks to retrieve and how to combine them with the query both have a large effect on answer quality.

    Pick the retriever for the kind of data, too. A Unity Catalog function that checks a live orders database fetches data for a different question. It is not the component that grounds a documentation answer. Guardrails can sit anywhere in this chain: filtering requests, checking permissions before a data source is touched, and moderating what is generated.

    Checkpoint 1 of 9· Put it in order

    A support bot must answer product questions from documentation chunks in a Databricks AI Search index and return the answer with citations. Put its RAG chain components in the order they run at inference time.

    1. 1.Output parser applies business logic and adds citations to the raw response
    2. 2.Prompt template combines the user's query, the retrieved chunks and instructions
    3. 3.Retriever embeds the retrieval query and returns the top-k most similar chunks
    4. 4.LLM generates a response grounded in the augmented prompt
    5. 5.Query understanding rewrites the raw user text into a retrieval query

    Checkpoint 2 of 9· Exam question

    A team is building a RAG-based customer support chain on Databricks. The chain must fetch the most relevant product documentation chunks from a Databricks AI Search (Vector Search) index before the LLM generates an answer. Which chain component should the team add immediately before the LLM call to supply this grounding context?

    Sources1

    2.Query understanding when inputs vary in kind

    If users phrase questions the same way your documents are written, the raw query can work as the retrieval query. Real inputs are messier: misspellings, follow-ups that only make sense with chat history, and terms that differ from the vocabulary in the documents. Query understanding is the first component of the chain. It reshapes the input before anything is retrieved.

    It does three main jobs:

    • Query rewriting: paraphrasing conversation history, correcting spelling, or swapping in synonyms so the query matches the documents' terms.
    • Filter extraction: pulling time periods ("reports from 2023"), products, or places out of the query and passing them to the retriever as parameters.
    • Intent classification: sorting the query into categories such as "product information", "troubleshooting" or "account management" before extracting entities and rewriting.

    Add intent classification as a front-end component when the inputs vary in kind, because the intent decides which entities matter and how to rewrite the query. The techniques themselves are covered in Intent detection on user input. One LLM call can do all of this, but splitting classification, extraction and rewriting into separate calls adds latency and gives finer control over each step.

    These components are coupled to their neighbours. A rewritten query only helps if the retriever is tuned for the new form. An extracted filter does nothing unless the data pipeline stored that metadata on each chunk and the retriever accepts the filter. If you add the front-end step without changing the components after it, retrieval gets no better.

    Checkpoint 3 of 9· Check yourself

    After adding an LLM step that pulls years such as "reports from 2023" out of user questions and passes them to the retriever as a filter, a team sees no change in retrieval quality. What is the most likely cause?

    Sources2

    3.Choosing the retriever from the shape of the query

    Two questions decide the retriever: where the answer lives, and what the query looks like. A RAG chain can query a vector store, a keyword search, or a SQL database. The supporting data can be unstructured (PDFs, wikis, documents) or structured (customer records, SQL transaction data, application APIs).

    Retrieval strategy by query shape, for unstructured documents
    StrategyMatches onQuery shape it wins onHow it works
    Semantic searchShared concepts"how do i turn my phone on?" against a section titled "toggling the power"Embeddings in a continuous vector space
    Keyword searchShared words, scored by frequency"what does model HD7-8D do?": specific, non-descriptive technical terms and product namesToken methods such as bag-of-words, TF-IDF, BM25
    Hybrid searchBoth"how do I turn on my HD7-8D?": concept plus exact termRuns both, then combines with reciprocal rank fusion or a re-ranking model

    On Databricks, you set this choice on the retriever itself. VectorSearchRetrieverTool takes query_type as "ANN" for approximate nearest-neighbour semantic search or "HYBRID" for hybrid search. num_results is the top-k, and filters is where the output of filter extraction goes.

    Retriever settings that follow from the query: top-k, filters, and semantic vs hybridpython
    vs_tool = VectorSearchRetrieverTool(
      index_name="catalog.schema.index_name", # Index name in the format 'catalog.schema.index'
      num_results=5, # Max number of documents to return
      columns=["primary_key", "text_column"], # List of columns to include in the search
      filters={"text_column LIKE": "Databricks"}, # Filters to apply to the query
      query_type="ANN", # Query type ("ANN" or "HYBRID").

    A query about a specific record or a current value calls for a different component. "Can you help me return my last order?" needs the order row from a database and the return policy from a document, so the system queries one source and retrieves from the other. A vector index answers from whatever the data pipeline last chunked and embedded. A structured tool runs its query against the table at the moment it is called. For inventory counts that change every few minutes, the right component is a Unity Catalog function tool that queries the live table. An index re-embedded once a day, or yesterday's counts pasted into the prompt, is the wrong choice.

    How much of the query the agent writes decides which structured option to use:

    • Unity Catalog SQL function, exposed through UCFunctionToolkit: the SQL is written in advance and the agent supplies only the parameters, for example a customer ID.
    • Genie: users or agents ask open-ended natural-language questions over a curated set of tables, and Genie generates the SQL. Genie Spaces are now called Genie Agents.
    • Databricks SQL MCP: the agent itself needs to write and run SQL against Unity Catalog tables.
    Wrapping Unity Catalog functions as agent tools with UCFunctionToolkitpython
    from databricks_langchain import UCFunctionToolkit
    from unitycatalog.ai.core.databricks import DatabricksFunctionClient
    
    toolkit = UCFunctionToolkit(
        function_names=[
            "main.default.databricks_docs_vector_search"
        ],
        client=DatabricksFunctionClient(),
    )
    tools = toolkit.tools

    Checkpoint 4 of 9· Check yourself

    Users of a parts-support assistant write questions like "why does my X-4410 pump keep stalling?". These mix a described problem with an exact part number. The VectorSearchRetrieverTool is set to query_type="ANN", and the returned chunks often cover similar problems on the wrong part. Which change fits this query shape?

    Checkpoint 5 of 9· Exam question

    An agent needs to answer questions about current inventory counts that change every few minutes; a static vector search index over product documentation would quickly become stale. Which chain component should the team add so the agent can fetch this real-time data on demand?

    Sources3456

    4.The prompt template and the LLM

    The prompt template is where retrieved context becomes model input. It places the user's query and the retrieved chunks inside instructions that tell the model how to use each one, and often how to format the answer. Getting this template right through iteration is what prompt engineering means in a chain. That is why a template is chosen together with the retriever: it has to fit the number and shape of the chunks the retriever returns.

    The LLM component is a choice of model and its parameters, made to balance performance, latency and cost for this specific step. A step that only classifies intent and a step that writes a grounded multi-paragraph answer can use different models, because each LLM call in the chain is its own component.

    Checkpoint 6 of 9· Check yourself

    In a RAG chain, an intent-classification step and the final grounded-answer step both call the same large model. Latency is too high, and the answers are good. Which component decision fits the chain?

    Sources12

    5.The output side: who reads the result

    The last component depends on who reads the output. If a person reads it, post-processing can be light: apply business rules, add citations, run moderation. If a downstream service parses it, the chain needs an output parser that enforces a fixed structure, and the model call should be constrained to produce that structure in the first place. Databricks recommends structured outputs for extraction across many documents, batch inference that needs a specified format, and turning unstructured data into structured data.

    "Respond in JSON" is not a schema. Databricks chat models can return free text, unconstrained JSON objects (json_object, intended for when the schema is not known in advance), or JSON that matches a declared schema (json_schema with strict). Only the last one fixes the fields. A service that expects sentiment, confidence and key_phrases needs that schema declared and the response validated against it after the LLM call. Lowering the temperature makes text more consistent, but it does not create fields. Retrieving example JSON adds context, but it does not enforce anything. Simpler, flatter schemas produce higher-quality JSON. The request mechanics are covered in Structured outputs with response_format and JSON schema.

    Function calling also produces structured output, but for a different purpose. The model emits a JSON object of arguments, your code calls the function, and the result goes back to the model. The model itself never calls the function. Use it when the output is an action to take. For pure conversion of data into structure, use structured outputs instead.

    Checkpoint 7 of 9· Match them up

    Match each way of producing the final output to the situation it fits at the end of a chain.

    Tap a term, then the definition that fits it.

    Checkpoint 8 of 9· Exam question

    A generative AI application must return LLM responses as a JSON object with fixed fields (sentiment, confidence, key_phrases) so a downstream service can parse the result without regex post-processing. Which chain component should the team add after the LLM call to guarantee this structure?

    Sources78

    6.Fixed transformation or steps that depend on results

    The last decision is whether the components run in a fixed order or whether the model chooses them. The full range of design patterns is covered in Deterministic chain vs single agent vs multi-agent supervisor. Here the test is the desired output. If it is a fixed transformation (retrieve, augment, generate, parse, the same way every time), a deterministic chain fits, because the developer sets the components, their order and their parameters. If the output is an action whose next step depends on what an earlier step returned, such as retrying an order lookup after an "invalid order number" response, the LLM needs to choose which tool to call next. That calls for an agent, and the retrievers and function tools above become its tools.

    Checkpoint 9 of 9· Check yourself

    Which of these applications needs an agent instead of a deterministic chain to produce its output?

    Sources4

    Sources

    (8)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “The top (most similar) results are returned.”
      ↩︎ The chain as an input-to-output pipeline
      “determining how many chunks to retrieve in step 2 and how to combine them with the user's query in step 3”
      ↩︎ The chain as an input-to-output pipeline
      “The LLM's response may be processed further to apply additional business logic, add citations, or otherwise refine the generated text”
      ↩︎ The chain as an input-to-output pipeline
      “augmenting the user's query with the retrieved context, in a template that instructs the model how to use each component”
      ↩︎ The prompt template and the LLM
      “chain of steps that are invoked at inference time is commonly referred to as the RAG chain”
      ↩︎ Key concept
    2. 2.
      “Analyzing and transforming user queries to better represent intent and extract relevant information”
      ↩︎ Query understanding when inputs vary in kind
      “Filter extraction must be done in conjunction with changes to both metadata extraction data pipeline and retriever chain components”
      ↩︎ Query understanding when inputs vary in kind
      “Intent classification: Use an LLM to classify the user's query into predefined categories”
      ↩︎ Query understanding when inputs vary in kind
      “Selecting the most appropriate model (and model parameters) for your application to optimize/balance performance, latency, and cost.”
      ↩︎ The prompt template and the LLM
      “Query rewriting must be done in conjunction with changes to the retrieval component”
      ↩︎ Exam trap 3
      “Customer support where queries contain specific, non descriptive technical terms.”
      ↩︎ Exam trap 4
      “Runs BOTH a semantic search and keyword search, then combines the results.”
      ↩︎ Prediction
      “Customer support queries that combined both semantic and technical terms. Example: “how do I turn on my HD7-8D?””
      ↩︎ Checkpoint
      “LLM: Selecting the most appropriate model (and model parameters) for your application to optimize/balance performance, latency, and cost.”
      ↩︎ Checkpoint
    3. 3.
      “The user's request is used to query an outside knowledge base such as a vector store, keyword search, or SQL database.”
      ↩︎ Choosing the retriever from the shape of the query
      “RAG architecture can work with either unstructured or structured supporting data.”
      ↩︎ Choosing the retriever from the shape of the query
      “Understand the user's question. Retrieve supporting data. Augment the prompt with supporting data. Generate a response from an LLM using the augmented prompt.”
      ↩︎ Checkpoint
    4. 4.
      “The agent queries the order database to retrieve the relevant order and references a policy document.”
      ↩︎ Choosing the retriever from the shape of the query
      “the developer defines which tools or models are called, in what order, and with which parameters”
      ↩︎ Fixed transformation or steps that depend on results
      “The LLM adaptively decides which tools to use, when to make more LLM calls, and when to stop.”
      ↩︎ Fixed transformation or steps that depend on results
      “If that tool responds with "invalid order number," the agent can retry or prompt the user for the correct ID”
      ↩︎ Checkpoint
    5. 5.
      “Use the Databricks SQL MCP when your agent needs to write and run SQL against your Unity Catalog tables.”
      ↩︎ Choosing the retriever from the shape of the query
      “when the query is known ahead of time and the agent provides the parameters”
      ↩︎ Exam trap 1
    6. 6.
      “Enables users to ask natural language questions to query enterprise data directly.”
      ↩︎ Choosing the retriever from the shape of the query
      “Genie Agents were formerly known as Genie Spaces.”
      ↩︎ Choosing the retriever from the shape of the query
    7. 7.
      “Batch inference tasks that require outputs to be in a specified format.”
      ↩︎ The output side: who reads the result
      “using a simpler JSON schema for JSON schema definitions results in higher quality JSON generation”
      ↩︎ The output side: who reads the result
      “You can choose to generate text, unstructured JSON objects, and JSON objects that adhere to a specific JSON schema.”
      ↩︎ Exam trap 2
      “You can choose to generate text, unstructured JSON objects, and JSON objects that adhere to a specific JSON schema.”
      ↩︎ Checkpoint

    Ready to test yourself?

    Practise the 6 questions on this subdomain.

    Spotted a mistake, or was something unclear? Tell us.