Langchain: Script fails sometimes


I am using langchain 4 python to create an agent and run 2 tools.
It is supposed to take input queries about songs and return the API calls to spotify one needs to make.

About half of times, my script works, returns Final answer and completes normally.
But other times, it fails with below error:

File "C:\Users\xxx\AppData\Local\Programs\Python\Python312\Lib\site-packages\langchain\agents\mrkl\", line 67, in parse
raise OutputParserException(
langchain_core.exceptions.OutputParserException: Could not parse LLM output: `I am finished executing a plan and have the information the user asked for.`

The problem is rather than returning the full response with {Action, Action Input, Observation, Thought and Final Answer}, it just returns the Thought string and fails in output parser.
And it’s not inability to find answer, cos in the last call where it fails, the Final answer is already in the prompt.

Please help me fix the issue.

Relevant Code:

os.environ['OPENAI_API_VERSION'] = "2023-07-01-preview"
os.environ['AZURE_OPENAI_ENDPOINT'] = ""
llm = AzureChatOpenAI(deployment_name="azure-gpt4turbo", temperature=0.0)

tools = [
        _create_api_planner_tool(api_spec, llm),
        _create_api_constructor_tool(api_spec, llm),
    prompt = PromptTemplate(
        input_variables=["input", "agent_scratchpad"],
            "tool_names": ", ".join([ for tool in tools]),
            "tool_descriptions": "\n".join(
                [f"{}: {tool.description}" for tool in tools]
    agent = ZeroShotAgent(
        llm_chain=LLMChain(llm=llm, prompt=prompt, memory=shared_memory),
        allowed_tools=[ for tool in tools],return_direct=True,
    return AgentExecutor.from_agent_and_tools(
        **(agent_executor_kwargs or {}),