OutputParserException
langchain.schema.output_parser.OutputParserException
Stack trace
langchain_core.exceptions.OutputParserException: Could not parse LLM output from parallel tool calls: `{"tool1": "result1", "tool2": "result2"}` does not match expected schema Why it happens
When calling multiple tools in parallel, the LLM may return combined or nested outputs that do not match the single-tool output schema expected by the parser. This mismatch causes the parser to raise an OutputParserException because it cannot deserialize or validate the aggregated response.
Detection
Wrap the parsing logic in try/except OutputParserException and log the raw combined LLM response to detect format mismatches before the error crashes the app.
Causes & fixes
LLM returns combined JSON objects for multiple tools instead of separate outputs
Adjust the parser to handle a dictionary of tool outputs or parse each tool's response individually.
Prompt instructions do not specify distinct output formats per tool in parallel calls
Update the prompt to clearly instruct the LLM to output each tool's result in a separate, well-defined JSON field.
Using a single-tool output parser on multi-tool parallel call responses
Use or implement a composite output parser that can parse multiple tool outputs simultaneously.
Code: broken vs fixed
from langchain.schema.output_parser import JsonOutputParser
# This parser expects a single JSON object, but parallel calls return multiple tool outputs
parser = JsonOutputParser()
response = '{"tool1": "result1", "tool2": "result2"}'
parsed = parser.parse(response) # Raises OutputParserException here import os
from langchain.schema.output_parser import JsonOutputParser
# Use a composite parser or custom logic for parallel tool outputs
parser = JsonOutputParser()
response = '{"tool1": "result1", "tool2": "result2"}'
# Parse the full response as JSON dict
parsed = parser.parse(response) # Works if parser supports dict
print(parsed)
# Environment variable usage for API keys example
os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY') # Ensure keys are set Workaround
Catch OutputParserException, then manually extract each tool's output from the raw LLM response string using regex or json.loads before parsing individually.
Prevention
Design prompts and output parsers to explicitly handle multiple tool outputs as structured dictionaries, or use API-level structured response formats to avoid parser mismatches.