langchain - 💡(How to fix) Fix feat(core): Add EChartsOutputParser for structured chart generation [1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langchain-ai/langchain#36735Fetched 2026-04-16 06:35:45
View on GitHub
Comments
1
Participants
1
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
labeled ×2commented ×1

Error Message

  • Full test coverage with 20 unit tests covering parsing, validation, streaming, format instructions, and error handling

Code Example

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

---

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"})
RAW_BUFFERClick to expand / collapse

Checked other resources

  • This is a feature request, not a bug report or usage question.
  • I added a clear and descriptive title that summarizes the feature request.
  • I used the GitHub search to find a similar feature request and didn't find it.
  • I checked the LangChain documentation and API reference to see if this feature already exists.
  • This is not related to the langchain-community package.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-openrouter
  • langchain-perplexity
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

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:

  1. Parse LLM text output (including markdown code blocks) into a JSON object representing an ECharts option
  2. Validate that the parsed object contains the required series property (must be an array)
  3. Provide format instructions that guide the LLM to produce valid ECharts option structures, with examples for common chart types (bar, line, pie, scatter, etc.)
  4. Support streaming by inheriting from JsonOutputParserBaseCumulativeTransformOutputParser
  5. 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

  1. 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.

  2. 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.

  3. 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

extent analysis

TL;DR

Implement an EChartsOutputParser class in langchain-core to parse LLM output into a valid ECharts option configuration object.

Guidance

  • Review the proposed EChartsOutputParser class implementation to ensure it correctly inherits from JsonOutputParser and overrides the necessary methods for ECharts-specific validation and format instructions.
  • Verify that the parser correctly handles streaming and raises descriptive OutputParserException errors when the output is invalid.
  • Test the parser with various input scenarios, including different chart types and invalid output, to ensure it works as expected.
  • Consider adding additional format instructions and examples for common chart types to improve the usability of the parser.

Example

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

Notes

The implementation of the EChartsOutputParser class should be reviewed to ensure it meets the requirements and is consistent with the existing codebase. Additionally, the parser's performance and error handling should be thoroughly tested to ensure it works correctly in different scenarios.

Recommendation

Apply the proposed solution by implementing the EChartsOutputParser class in langchain-core, as it provides a clear and concise way to parse LLM output into a valid ECharts option configuration object, and it has no external dependencies.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING