Bug/error with LLM call in the graded assignment - Module 1

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}}
---------------------------------------------------------------------------
BadRequestError                           Traceback (most recent call last)
Cell In[43], line 1
----> 1 print(llm_call(query, use_rag = True))

Cell In[41], line 19, in llm_call(query, top_k, use_rag, prompt)
     16 prompt = generate_final_prompt(query, top_k, use_rag, prompt)
     18 # Call the LLM
---> 19 generated_response = generate_with_single_input(prompt)
     21 # Get the content
     22 generated_message = generated_response['content']

File ~/work/utils.py:104, in generate_with_single_input(prompt, role, top_p, temperature, max_tokens, model, together_api_key, **kwargs)
    102         payload['temperature'] = None
    103     client = Together(api_key =  together_api_key)
--> 104     json_dict = client.chat.completions.create(**payload).model_dump()
    105     json_dict['choices'][-1]['message']['role'] = json_dict['choices'][-1]['message']['role'].lower()
    106 try:

Your are right.

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:

generated_response = generate_with_single_input(prompt, role='user')

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.

Retrieval Augmented Generation (RAG) Module 1 > Introduction to RAG Systems > Graded Code Assignment

We are unable to edit the cell in question:

print(llm_call(query, use_rag = True))

“All cells are frozen except for the ones where you need to submit your solutions or when explicitly mentioned you can interact with it.”

Hi Reed, Welcome to the forum!

Two key things here:

1. It does not affect your grade

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:

def llm_call_fixed(query, top_k=5, use_rag=True, prompt=None):
    prompt = generate_final_prompt(query, top_k, use_rag, prompt)
    return generate_with_single_input(prompt, role="user")['content']

print(llm_call_fixed(query, use_rag=True))

Option B: Fix utils.py directly

  1. Click File → Open... in the Jupyter menu.
  2. Open utils.py.
  3. In line 65, change role: str = 'assistant' to role: str = 'user'.
  4. Save the file, return to the notebook, and run Kernel → Restart & Clear Output. The original frozen cells will now run without errors.

@arman101, does the course need to be updated?

maybe yes

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

Issue raised at GitHub.

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.