-
Notifications
You must be signed in to change notification settings - Fork 21.5k
Description
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.