[PR #1939] [MERGED] fix(langgraph-api): enhance cli JSON schema extraction #1857

Closed
opened 2026-02-15 20:17:05 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/langgraphjs/pull/1939
Author: @hntrl
Created: 2/3/2026
Status: Merged
Merged: 2/4/2026
Merged by: @hntrl

Base: mainHead: hunter/cli-schema-extraction


📝 Commits (4)

  • 4f5c1e5 fix(langgraph-api): enhance runtime JSON schema extraction with multi-tier strategy
  • c8d20ec feat(langgraph-api): enhanced JSON schema extraction for Studio
  • 393d5b6 cr
  • 3af117b cr

📊 Changes

10 files changed (+588 additions, -10 deletions)

View changed files

.changeset/enhanced-schema-extraction.md (+15 -0)
📝 libs/langgraph-api/src/api/assistants.mts (+0 -1)
📝 libs/langgraph-api/src/graph/parser/index.mts (+172 -2)
📝 libs/langgraph-api/tests/api.test.mts (+96 -1)
📝 libs/langgraph-api/tests/graphs/langgraph.json (+4 -1)
libs/langgraph-api/tests/graphs/plain_zod_graph.mts (+28 -0)
libs/langgraph-api/tests/graphs/state_schema_graph.mts (+36 -0)
libs/langgraph-api/tests/graphs/zod_registry_graph.mts (+38 -0)
📝 libs/langgraph-api/tests/parser.test.mts (+184 -0)
📝 libs/sdk/.eslintrc.cjs (+15 -5)

📄 Description

Enhances the JSON schema extraction for LangGraph Studio by implementing a multi-tier extraction strategy.

Fixes #1938

Changes

Enhanced getRuntimeGraphSchema() with Multi-Tier Extraction

The schema extraction for Studio now follows this priority order:

  1. StateSchema - Native JSON schema via getJsonSchema() and getInputJsonSchema()

    • Handles jsonSchemaExtra from ReducedValue instances
    • Supports PartialStateSchema symbol for input inheritance
  2. Zod Registry - Via existing getUpdateTypeSchema() etc.

    • Preserves jsonSchemaExtra from withLangGraph() calls
    • Uses global schemaMetaRegistry for metadata lookup
  3. Direct Zod - Fallback conversion without registry

    • Handles both Zod v3 (via zod-to-json-schema) and Zod v4 (via native z.toJSONSchema())
    • Falls through when schemas aren't registered with withLangGraph()
  4. Static TypeScript Parser - Unchanged fallback to AST-based extraction

New Helper Functions

  • tryStateSchemaExtraction() - Checks for StateSchema instances and extracts JSON schemas
  • tryZodRegistryExtraction() - Preserved existing Zod logic with registry metadata
  • tryDirectZodExtraction() - Direct Zod conversion fallback for unregistered schemas

Test Coverage

Added comprehensive unit tests in tests/parser.test.mts:

  • StateSchema with plain fields
  • StateSchema with ReducedValue and jsonSchemaExtra
  • Zod with withLangGraph
  • Plain Zod without registry
  • Priority order verification
  • Edge cases (graph without builder)

Files Changed

File Changes
libs/langgraph-api/src/graph/parser/index.mts +154 lines - Multi-tier extraction implementation
libs/langgraph-api/tests/parser.test.mts +184 lines - Unit tests for runtime extraction

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langchain-ai/langgraphjs/pull/1939 **Author:** [@hntrl](https://github.com/hntrl) **Created:** 2/3/2026 **Status:** ✅ Merged **Merged:** 2/4/2026 **Merged by:** [@hntrl](https://github.com/hntrl) **Base:** `main` ← **Head:** `hunter/cli-schema-extraction` --- ### 📝 Commits (4) - [`4f5c1e5`](https://github.com/langchain-ai/langgraphjs/commit/4f5c1e5f69c585aab4a4f4a9f645f5e1e03b8a46) fix(langgraph-api): enhance runtime JSON schema extraction with multi-tier strategy - [`c8d20ec`](https://github.com/langchain-ai/langgraphjs/commit/c8d20ec62407c129113aecd17f1161ca6522bcef) feat(langgraph-api): enhanced JSON schema extraction for Studio - [`393d5b6`](https://github.com/langchain-ai/langgraphjs/commit/393d5b6d78f642ccf27bebc3ac9d6f052e6097e4) cr - [`3af117b`](https://github.com/langchain-ai/langgraphjs/commit/3af117be9b69da902ba15927937d68d336c505e0) cr ### 📊 Changes **10 files changed** (+588 additions, -10 deletions) <details> <summary>View changed files</summary> ➕ `.changeset/enhanced-schema-extraction.md` (+15 -0) 📝 `libs/langgraph-api/src/api/assistants.mts` (+0 -1) 📝 `libs/langgraph-api/src/graph/parser/index.mts` (+172 -2) 📝 `libs/langgraph-api/tests/api.test.mts` (+96 -1) 📝 `libs/langgraph-api/tests/graphs/langgraph.json` (+4 -1) ➕ `libs/langgraph-api/tests/graphs/plain_zod_graph.mts` (+28 -0) ➕ `libs/langgraph-api/tests/graphs/state_schema_graph.mts` (+36 -0) ➕ `libs/langgraph-api/tests/graphs/zod_registry_graph.mts` (+38 -0) 📝 `libs/langgraph-api/tests/parser.test.mts` (+184 -0) 📝 `libs/sdk/.eslintrc.cjs` (+15 -5) </details> ### 📄 Description Enhances the JSON schema extraction for LangGraph Studio by implementing a multi-tier extraction strategy. Fixes #1938 ## Changes ### Enhanced `getRuntimeGraphSchema()` with Multi-Tier Extraction The schema extraction for Studio now follows this priority order: 1. **StateSchema** - Native JSON schema via `getJsonSchema()` and `getInputJsonSchema()` - Handles `jsonSchemaExtra` from `ReducedValue` instances - Supports `PartialStateSchema` symbol for input inheritance 2. **Zod Registry** - Via existing `getUpdateTypeSchema()` etc. - Preserves `jsonSchemaExtra` from `withLangGraph()` calls - Uses global `schemaMetaRegistry` for metadata lookup 3. **Direct Zod** - Fallback conversion without registry - Handles both Zod v3 (via `zod-to-json-schema`) and Zod v4 (via native `z.toJSONSchema()`) - Falls through when schemas aren't registered with `withLangGraph()` 4. **Static TypeScript Parser** - Unchanged fallback to AST-based extraction ### New Helper Functions - `tryStateSchemaExtraction()` - Checks for `StateSchema` instances and extracts JSON schemas - `tryZodRegistryExtraction()` - Preserved existing Zod logic with registry metadata - `tryDirectZodExtraction()` - Direct Zod conversion fallback for unregistered schemas ### Test Coverage Added comprehensive unit tests in `tests/parser.test.mts`: - StateSchema with plain fields - StateSchema with `ReducedValue` and `jsonSchemaExtra` - Zod with `withLangGraph` - Plain Zod without registry - Priority order verification - Edge cases (graph without builder) --- ## Files Changed | File | Changes | |------|---------| | `libs/langgraph-api/src/graph/parser/index.mts` | +154 lines - Multi-tier extraction implementation | | `libs/langgraph-api/tests/parser.test.mts` | +184 lines - Unit tests for runtime extraction | --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-15 20:17:05 -05:00
yindo closed this issue 2026-02-15 20:17:05 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraphjs#1857