langchain - ✅(Solved) Fix [Feature Request]: Add ECharts Output Parser to core [2 pull requests, 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#36102Fetched 2026-04-08 01:01:57
View on GitHub
Comments
1
Participants
1
Timeline
8
Reactions
0
Author
Participants
Timeline (top)
labeled ×4cross-referenced ×2commented ×1issue_type_added ×1

Error Message

Currently, I have to manually parse JSON or write custom regex to extract chart options, which is error-prone. This feature would help users to seamlessly integrate LLM-generated charts into Dashboards (React, Vue, etc.) without worrying about parsing logic or formatting inconsistencies. I'm trying to build an application that generates dynamic data visualizations using LLMs. Currently, I have to manually parse JSON responses or write custom regex to extract chart configurations from LLM outputs, which is error-prone and inconsistent. Custom regex parsing - error-prone and breaks with different LLM response formats

Root Cause

But these don't work because they either lack validation or require too much manual intervention.

Fix Action

PR fix notes

PR #36101: Closes #36102

Description (problem / solution / changelog)

Fixes #

<!-- Replace everything above this line with a 1-2 sentence description of your change. Keep the "Fixes #xx" keyword and update the issue number. -->

Read the full contributing guidelines: https://docs.langchain.com/oss/python/contributing/overview

All contributions must be in English. See the language policy.

If you paste a large clearly AI generated description here your PR may be IGNORED or CLOSED!

Thank you for contributing to LangChain! Follow these steps to have your pull request considered as ready for review.

  1. PR title: Should follow the format: TYPE(SCOPE): DESCRIPTION
  1. PR description:
  • Write 1-2 sentences summarizing the change.
  • The Fixes #xx line at the top is required for external contributions — update the issue number and keep the keyword. This links your PR to the approved issue and auto-closes it on merge.
  • If there are any breaking changes, please clearly describe them.
  • If this PR depends on another PR being merged first, please include "Depends on #PR_NUMBER" in the description.
  1. Run make format, make lint and make test from the root of the package(s) you've modified.
  • We will not consider a PR unless these three are passing in CI.
  1. How did you verify your code works?

Additional guidelines:

  • All external PRs must link to an issue or discussion where a solution has been approved by a maintainer, and you must be assigned to that issue. PRs without prior approval will be closed.
  • PRs should not touch more than one package unless absolutely necessary.
  • Do not update the uv.lock files or add dependencies to pyproject.toml files (even optional ones) unless you have explicit permission to do so by a maintainer.

Social handles (optional)

<!-- If you'd like a shoutout on release, add your socials below -->

Twitter: @ LinkedIn: https://linkedin.com/in/

Changed files

  • libs/core/langchain_core/output_parsers/__init__.py (modified, +3/-0)
  • libs/core/langchain_core/output_parsers/echarts.py (added, +59/-0)
  • libs/core/tests/unit_tests/output_parsers/test_echarts.py (added, +44/-0)
  • test.py (added, +0/-0)

PR #36103: Closes #36102

Description (problem / solution / changelog)

Description

This PR adds a new EChartsOutputParser to langchain-core. This specialized parser extracts JSON objects that conform to the Apache ECharts 'option' configuration, making it easy for developers to generate charts directly from LLM outputs.

Key Features:

  • Inherits from BaseOutputParser[dict] for standard compliance.
  • Robust parsing using parse_json_markdown to handle varying model output styles.
  • Professional docstrings with experimental warnings.
  • Fully tested with unit tests in libs/core.

Associated Issue

Closes #36102

AI Disclaimer

This contribution was assisted by an AI agent.

Changed files

  • libs/core/langchain_core/output_parsers/__init__.py (modified, +3/-0)
  • libs/core/langchain_core/output_parsers/echarts.py (added, +59/-0)
  • libs/core/tests/unit_tests/output_parsers/test_echarts.py (added, +44/-0)
  • test.py (added, +0/-0)
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 LangChain to support a specialized ECharts Output Parser in langchain-core.

This feature would allow users to reliably parse LLM responses into a JSON dictionary that follows the Apache ECharts 'option' configuration schema. It should handle markdown-wrapped JSON and provide clear format instructions to ensure the model produces valid chart configurations.

Use Case I am building an application that uses LLMs to generate dynamic data visualizations on the fly.

Currently, I have to manually parse JSON or write custom regex to extract chart options, which is error-prone. This feature would help users to seamlessly integrate LLM-generated charts into Dashboards (React, Vue, etc.) without worrying about parsing logic or formatting inconsistencies.

Proposed Solution I think this could be implemented as a new class

EChartsOutputParser inheriting from BaseOutputParser[dict] in

libs/core/langchain_core/output_parsers/echarts.py .

Use Case

I'm trying to build an application that generates dynamic data visualizations using LLMs. Currently, I have to manually parse JSON responses or write custom regex to extract chart configurations from LLM outputs, which is error-prone and inconsistent.

This feature would help users to seamlessly integrate LLM-generated ECharts visualizations into web applications (React, Vue, dashboards, etc.) without worrying about parsing logic or format inconsistencies. It would ensure that the LLM output consistently follows the ECharts option schema.

Proposed Solution

I think this could be implemented as a new class EChartsOutputParser inheriting from BaseOutputParser[dict] in libs/core/langchain_core/output_parsers/echarts.py.

The API could look like:

from langchain_core.output_parsers import EChartsOutputParser
from langchain_core.prompts import PromptTemplate

parser = EChartsOutputParser()
prompt = PromptTemplate(
    template="Generate an ECharts option for {data}\n{format_instructions}",
    input_variables=["data"],
    partial_variables={"format_instructions": parser.get_format_instructions()}
)

chain = prompt | model | parser
result = chain.invoke({"data": "sales figures for Q1 2024"})
# result is a validated dict matching ECharts schema

### Alternatives Considered

JsonOutputParser - but it doesn't validate against ECharts specific schema

Custom regex parsing - error-prone and breaks with different LLM response formats

Manual JSON parsing - fails when the model adds explanatory text

Alternative approaches I considered:

Creating a custom prompt template - but this doesn't guarantee consistent output format

Using Pydantic models - but ECharts has a complex, flexible schema that's difficult to model statically

But these don't work because they either lack validation or require too much manual intervention.

text

### 4. **Additional Context** (optional)
Related issues: This would complement existing visualization tools in the LangChain ecosystem.

Similar features in other libraries:

None that I'm aware of specifically for ECharts

Additional context:
ECharts is one of the most popular charting libraries (used by Apache, Baidu, etc.) with over 60k GitHub stars. Supporting it natively would benefit many developers building data applications with LLMs.

### Additional Context

ECharts is one of the most popular charting libraries (used by Apache, Baidu, etc.) with over 60k GitHub stars. Supporting it natively would benefit many developers building data applications with LLMs.

extent analysis

Fix Plan

To implement the ECharts Output Parser, follow these steps:

  • Create a new file echarts.py in libs/core/langchain_core/output_parsers/ with the following content:
from langchain_core.output_parsers import BaseOutputParser
from pydantic import ValidationError
from typing import Dict

class EChartsOutputParser(BaseOutputParser[Dict]):
    def parse(self, output: str) -> Dict:
        # Remove markdown wrapping and extract JSON
        output = output.strip().removeprefix("```json").removesuffix("```")
        try:
            # Validate against ECharts schema
            import json
            chart_config = json.loads(output)
            # Add validation logic here if needed
            return chart_config
        except (json.JSONDecodeError, ValidationError) as e:
            raise ValueError(f"Invalid ECharts configuration: {e}")

    def get_format_instructions(self) -> str:
        return "Please provide a valid ECharts option configuration in JSON format."
  • Update the __init__.py file in libs/core/langchain_core/output_parsers/ to include the new parser:
from .echarts import EChartsOutputParser
  • Use the new parser in your application:
from langchain_core.output_parsers import EChartsOutputParser
from langchain_core.prompts import PromptTemplate

parser = EChartsOutputParser()
prompt = PromptTemplate(
    template="Generate an ECharts option for {data}\n{format_instructions}",
    input_variables=["data"],
    partial_variables={"format_instructions": parser.get_format_instructions()}
)

chain = prompt | model | parser
result = chain.invoke({"data": "sales figures for Q1 2024"})
# result is a validated dict matching ECharts schema

Verification

To verify that the fix worked, test the parser with different inputs, including valid and invalid ECharts configurations. You can use the following example test cases:

import unittest

class TestEChartsOutputParser(unittest.TestCase):
    def test_valid_config(self):
        parser = EChartsOutputParser()
        output = '{"xAxis": {"type": "category"}, "yAxis": {"type": "value"}}'
        result = parser.parse(output)
        self.assertEqual(result, {"xAxis": {"type": "category"}, "yAxis": {"type": "value"}})

    def test_invalid_config(self):
        parser = EChartsOutputParser()
        output = '{"xAxis": {"type": " invalid"}}'
        with self.assertRaises(ValueError):
            parser.parse(output)

if __name__ == "__main__":
    unittest.main()

Extra Tips

  • Make sure to update the get_format_instructions method to provide clear instructions for the model to generate valid ECharts configurations.
  • Consider adding additional validation logic to the parse method to handle specific ECharts schema requirements.

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

langchain - ✅(Solved) Fix [Feature Request]: Add ECharts Output Parser to core [2 pull requests, 1 comments, 1 participants]