Checked other resources
Package (Required)
Feature Description
I would like to propose adding an EChartsOutputParser to langchain-core that parses LLM output into a valid ECharts option configuration object.
ECharts is one of the most popular open-source charting libraries, widely used in both English and Chinese-speaking developer communities. It uses a declarative JSON-based option object to describe charts, making it a natural fit for LLM-driven chart generation.
The parser would:
- Parse LLM text output (including markdown code blocks) into a JSON object representing an ECharts option
- Validate that the parsed object contains the required
series property (must be an array)
- Provide format instructions that guide the LLM to produce valid ECharts option structures, with examples for common chart types (bar, line, pie, scatter, etc.)
- Support streaming by inheriting from
JsonOutputParser → BaseCumulativeTransformOutputParser
- Optionally accept a Pydantic model for more precise schema-driven format instructions
Use Case
When building LLM-powered data analysis or reporting applications, users often want to generate interactive charts from natural language descriptions. For example:
- A data analyst asks an LLM agent to "create a bar chart showing quarterly sales" and expects a renderable chart configuration
- A reporting tool generates ECharts configurations from natural language summaries
- A dashboard builder uses an LLM to suggest chart types and configurations based on a dataset
Currently, users must manually parse LLM output as JSON and validate the ECharts option structure themselves. An EChartsOutputParser would streamline this workflow by:
- Providing clear format instructions so the LLM produces valid ECharts options
- Validating the
series property is present and correctly structured
- Supporting streaming for real-time chart rendering
- Raising descriptive
OutputParserException errors when the output is invalid, helping the LLM self-correct
Proposed Solution
Add an EChartsOutputParser class to langchain_core/output_parsers/echarts.py that:
- Inherits from
JsonOutputParser (which already handles JSON parsing, markdown code block extraction, and streaming)
- Overrides
parse_result() to add ECharts-specific validation:
- The result must be a JSON object (dict)
- The
series property must exist and be an array
- Overrides
get_format_instructions() to return ECharts-specific format guidance with:
- Description of the ECharts option structure
- List of common top-level properties (
title, tooltip, legend, xAxis, yAxis, series, dataset, grid, color)
- Examples for bar chart and pie chart
- Optional Pydantic schema when provided
- Sets
_type property to "echarts"
- Exports from
langchain_core.output_parsers
Example usage:
from langchain_core.output_parsers import EChartsOutputParser
parser = EChartsOutputParser()
result = parser.parse('''
{
"title": {"text": "Sales Report"},
"xAxis": {"type": "category", "data": ["Q1", "Q2", "Q3", "Q4"]},
"yAxis": {"type": "value"},
"series": [{"type": "bar", "data": [120, 200, 150, 80]}]
}
''')
# result is a dict that can be directly used as an ECharts option
With a chain:
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import EChartsOutputParser
prompt = ChatPromptTemplate.from_template(
"Generate an ECharts chart configuration for: {query}"
)
parser = EChartsOutputParser()
chain = prompt | model | parser
chart_option = chain.invoke({"query": "Monthly sales as a bar chart"})
Alternatives Considered
-
Using JsonOutputParser directly: Users could use JsonOutputParser and manually validate the ECharts structure, but this requires custom validation code and does not provide ECharts-specific format instructions to the LLM.
-
Placing in langchain-classic instead of langchain-core: Since ECharts is a specific library, one could argue it belongs in langchain-classic. However, the parser has zero external dependencies (it only validates JSON structure, not against the ECharts runtime), and output parsers for common structured formats (JSON, Pydantic, XML, List) already live in langchain-core. The ECharts option is essentially a JSON schema with domain-specific validation, similar to how PydanticOutputParser adds Pydantic validation on top of JSON parsing.
-
Creating a separate partner package: This would add unnecessary overhead for a lightweight parser with no external dependencies.
Additional Context
- ECharts has 64k+ GitHub stars and is the most popular charting library in the Chinese developer ecosystem
- The parser adds no new dependencies — it only uses existing
langchain-core utilities (parse_json_markdown, OutputParserException, etc.)
- The implementation is ~200 lines of code including docstrings and format instructions
- Full test coverage with 20 unit tests covering parsing, validation, streaming, format instructions, and error handling
- I have a working implementation ready to submit as a PR once this issue is approved
Checked other resources
Package (Required)
Feature Description
I would like to propose adding an
EChartsOutputParsertolangchain-corethat parses LLM output into a valid ECharts option configuration object.ECharts is one of the most popular open-source charting libraries, widely used in both English and Chinese-speaking developer communities. It uses a declarative JSON-based option object to describe charts, making it a natural fit for LLM-driven chart generation.
The parser would:
seriesproperty (must be an array)JsonOutputParser→BaseCumulativeTransformOutputParserUse Case
When building LLM-powered data analysis or reporting applications, users often want to generate interactive charts from natural language descriptions. For example:
Currently, users must manually parse LLM output as JSON and validate the ECharts option structure themselves. An
EChartsOutputParserwould streamline this workflow by:seriesproperty is present and correctly structuredOutputParserExceptionerrors when the output is invalid, helping the LLM self-correctProposed Solution
Add an
EChartsOutputParserclass tolangchain_core/output_parsers/echarts.pythat:JsonOutputParser(which already handles JSON parsing, markdown code block extraction, and streaming)parse_result()to add ECharts-specific validation:seriesproperty must exist and be an arrayget_format_instructions()to return ECharts-specific format guidance with:title,tooltip,legend,xAxis,yAxis,series,dataset,grid,color)_typeproperty to"echarts"langchain_core.output_parsersExample usage:
With a chain:
Alternatives Considered
Using
JsonOutputParserdirectly: Users could useJsonOutputParserand manually validate the ECharts structure, but this requires custom validation code and does not provide ECharts-specific format instructions to the LLM.Placing in
langchain-classicinstead oflangchain-core: Since ECharts is a specific library, one could argue it belongs inlangchain-classic. However, the parser has zero external dependencies (it only validates JSON structure, not against the ECharts runtime), and output parsers for common structured formats (JSON, Pydantic, XML, List) already live inlangchain-core. The ECharts option is essentially a JSON schema with domain-specific validation, similar to howPydanticOutputParseradds Pydantic validation on top of JSON parsing.Creating a separate partner package: This would add unnecessary overhead for a lightweight parser with no external dependencies.
Additional Context
langchain-coreutilities (parse_json_markdown,OutputParserException, etc.)