I am getting the below “Bad Request” error in the LLM Call function
print(llm_call(query, use_rag = True))
the method call generated_response = generate_with_single_input(prompt) misses a second parameter role = ‘user’ for the LLM call.
BadRequestError: Error code: 400 - {'error': {'type': 'invalid_request_error', 'code': 'process_messages_failed', 'message': 'Failed to apply chat template: Failed to render template: invalid operation: No user query found in messages. (in chat:79)', 'param': None}}
The chat template for the backend model strictly requires at least one message with role: "user". Calling generate_with_single_input(prompt) without a role argument defaults to a system role (or omits the user role), triggering process_messages_failed: No user query found in messages.
Update the call inside llm_call to pass role='user' explicitly:
llm_call is an ungraded helper cell used to test your pipeline. The autograder for Module 1 only grades get_relevant_data and format_relevant_data, so modifying this call will unblock your testing without affecting your score.
The autograder tests only Exercise 1 (get_relevant_data) and Exercise 2 (format_relevant_data). The llm_call cell and the experimentation section at the end are purely for demonstration. You can leave that cell unexecuted and submit the notebook.
2. Why the cell fails and why it is frozen
The non-graded cells are locked with "editable": false to prevent accidental edits to course boilerplate.
The error inside llm_call is a bug in utils.py: generate_with_single_input defaults to role='assistant', but the underlying chat model requires a user role to render the chat template properly, throwing a 400 Bad Request.
3. Workaround if you want to test the LLM output
If you want to see the model responses in action, use either option:
Option A: Insert a new cell
Click any cell, press B (or go to Insert → Insert Cell Below), and define a patched call:
Hi I was running in to this error today, was able to troubleshoot by updating utils.py but this should be patched just defaulting role: str = ‘user’ in the utils: def generate_with_single_input does the trick
I ran in the same issue in Module 1 / Ungraded Lab 2 as well @arman101 .
Qwen which is used requires a ‘user’ input so just passing ‘assistant’ will fail.