Find answers from the community

Updated 3 months ago

Hey everyone! I'm running into issues

Hey everyone! I'm running into issues building the links in my error-correction text-to-SQL agentic pipeline (based on the query pipeline documentation but different). I'm getting
Plain Text
ValueError: too many values to unpack (expected 2)
when running the link between response synthesis prompt and the llm, but all fixes I've tried have resulted in even more errors. Here's the relevant code:
Plain Text
llm = OpenAI(model='gpt-3.5-turbo', temperature = 0.0)


s_sql_retriever = SQLRetriever(sql_database)

# Needed to make function to output str
def s_sql_retriever_fn(task: Task, state: Dict[str, Any], sql_query: str) -> str:
    """Function to run the retriever."""
    node_with_score = s_sql_retriever.retrieve(sql_query)
    metadata = node_with_score[0].node.metadata
    output = {"result": metadata['result'], "col_keys": metadata['col_keys']}
    
    output_str = f"Retrieved columns: {output.get('col_keys', [])}\n SQL Response: {output.get('result', [])}"
    
    return output_str

s_sql_retriever_component = AgentFnComponent(fn=s_sql_retriever_fn)


s_response_synthesis_prompt_str = (
[instructions redacted]
    "Query: {query_str}\n"
    "SQL: {sql_query}\n"
    "{sql_result_and_col_keys_str}\n"
    # "Retrieved columns: {retrieved_cols}\n"
    # "SQL Response: {sql_response}\n"
    "Response: "
)
s_response_synthesis_prompt = PromptTemplate(
    s_response_synthesis_prompt_str
)


s_agent_qp = QP(
    modules={
        "input": s_agent_input_component,
        "table_retriever": s_obj_retriever_component,
        "table_output_parser": s_table_parser_component,
        "retry_prompt": s_prompt,
        "llm": llm,
        "sql_output_parser": s_parser_component,
        "sql_retriever": s_sql_retriever_component,
        "response_synthesis_prompt": s_response_synthesis_prompt,
        "response_synthesis_llm": llm,
        # "output_component": s_agent_output_component,
    },
    verbose=True,
)

Reached character limit so code/info continued in reply message ⬇️
d
L
5 comments
Plain Text
s_agent_qp.add_link("input", "table_retriever", src_key="input", dest_key="query")
s_agent_qp.add_link("table_retriever", "table_output_parser", src_key="output", dest_key="table_schema_objs")
s_agent_qp.add_link("input", "retry_prompt", src_key="input", dest_key="query_str")
s_agent_qp.add_link(
    "input", "retry_prompt", src_key="convo_history", dest_key="convo_history")
s_agent_qp.add_link("table_output_parser", "retry_prompt", dest_key="schema")
s_agent_qp.add_chain(["retry_prompt", "llm", "sql_output_parser"])
s_agent_qp.add_link("sql_output_parser", "sql_retriever", src_key="output", dest_key="sql_query")
s_agent_qp.add_link("sql_output_parser", "response_synthesis_prompt", dest_key="sql_query")
s_agent_qp.add_link("sql_retriever", "response_synthesis_prompt", dest_key="sql_result_and_col_keys_str")
s_agent_qp.add_chain(["response_synthesis_prompt", "response_synthesis_llm"])


# Wrap query pipeline into an agent
s_agent_worker = QueryPipelineAgentWorker(s_agent_qp)
s_agent = s_agent_worker.as_agent(callback_manager=CallbackManager([]), verbose=True)

# Now, use this agent as a tool for another agent
s_agent_tool = QueryEngineTool.from_defaults(
    query_engine=s_agent,
    name="agent_tool",
    description="A tool that wraps an advanced text-to-SQL agent",
)


answer = s_agent_tool.call("Who does Kevin Martinez report to?")


Note that the link between the first prompt and the llm works fine, it's just this one that errors.

Error below ⬇️
Plain Text
ValueError                                Traceback (most recent call last)
Cell In[161], line 1
----> 1 test_answer = s_agent_tool.call("Who does Kevin Martinez report to?")

File /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/llama_index/core/instrumentation/dispatcher.py:230, in Dispatcher.span.<locals>.wrapper(func, instance, args, kwargs)
    226 self.span_enter(
    227     id_=id_, bound_args=bound_args, instance=instance, parent_id=parent_id
    228 )
    229 try:
--> 230     result = func(*args, **kwargs)
    231 except BaseException as e:
    232     self.event(SpanDropEvent(span_id=id_, err_str=str(e)))

File /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/llama_index/core/tools/query_engine.py:68, in QueryEngineTool.call(self, *args, **kwargs)
     66 def call(self, *args: Any, **kwargs: Any) -> ToolOutput:
     67     query_str = self._get_query_str(*args, **kwargs)
---> 68     response = self._query_engine.query(query_str)
     69     return ToolOutput(
     70         content=str(response),
     71         tool_name=self.metadata.name,
     72         raw_input={"input": query_str},
     73         raw_output=response,
     74     )
...
    201     )
    202 else:
    203     agent_response, is_done = self.pipeline.run()

ValueError: too many values to unpack (expected 2)


I've been banging my head against the wall with this lately so any help is really appreciated, especially guidance from the llamaindex team.
@Logan M Could you please help me out with this?
the traceback seems to be truncated, so I can't tell what the actual issue is

tbh the query pipeline is low-key the worst to debug. I might recommend against using it. We recently moved away from it when we introduced workflows
@Logan M Thanks for the response. Unfortunately I’m unable to paste the entire error message here due to the character limit. Is there any chance I could schedule a call with either you or someone else on the LlamaIndex team to get guidance not only on this but mainly the development of my application as a whole? I’m very much a newbie so would greatly appreciate more direct mentorship regarding my approach to the project
Add a reply
Sign up and join the conversation on Discord