Databricks Generative AI Engineer Associate Question 197
Single answerYou are tasked with creating a simple chain in Databricks to generate a product description based on given product details. The chain needs to use a Large Language Model (LLM) and consist of two steps: (1) Parsing the input JSON to extract 'product_name' and 'features', and (2) Generating a description using these extracted fields. Which of the following implementations correctly fulfills this requirement?
- A
Use a custom Python function to parse the JSON and directly integrate it with the LLM's prompt template within a single step.
- B
Use a sequential chain with two steps: a JSON parser step for input extraction and an LLM step for generating the description.
- C
Use a single LLM step that both parses the JSON input and generates the description in one operation.
- D
Use a parallel chain to process JSON parsing and description generation simultaneously, then merge the outputs.
Show answer and explanation
Correct answer: B
Explanation
The correct approach to coding a chain is to ensure tasks are modular and sequential if they are dependent on each other. By using a sequential chain with separate steps for JSON parsing and LLM-based generation, the solution remains scalable, debuggable, and adheres to best practices for chain design in Databricks.
- A. Incorrect.
This option does not separate the responsibilities of parsing and description generation, which makes debugging and modularity difficult. It does not align with best practices for building chains.
- B. Correct.
This option correctly creates a sequential chain with clear separation of tasks: the JSON parsing and LLM-based description generation. It ensures modularity and adheres to best practices.
- C. Incorrect.
Using a single LLM step for both parsing and generation can lead to unstructured workflows and potential errors, as it combines unrelated tasks in one step.
- D. Incorrect.
This option is incorrect because parallel chains are not suitable for tasks that have a dependent sequence, such as parsing first and then generating the description.