Skip to content

[codex] Add Moonshot JSON schema response format#3279

Open
TuringTzu wants to merge 1 commit into
langgenius:mainfrom
TuringTzu:codex/moonshot-json-schema
Open

[codex] Add Moonshot JSON schema response format#3279
TuringTzu wants to merge 1 commit into
langgenius:mainfrom
TuringTzu:codex/moonshot-json-schema

Conversation

@TuringTzu

Copy link
Copy Markdown

Summary

  • add json_schema as a supported Moonshot response format option
  • expose the json_schema parameter on built-in Moonshot/Kimi LLM model schemas
  • convert Dify's response_format=json_schema parameter into Moonshot's structured output request shape
  • bump the Moonshot plugin manifest to 0.1.8

Why

Moonshot/Kimi's current API supports structured output through response_format: {"type": "json_schema"}, but the Dify Moonshot plugin only exposed text and json_object. This lets workflow LLM nodes use Dify's JSON Schema structured output mode with Moonshot models.

Validation

  • uv run ruff check models/llm/llm.py
  • python -m compileall models/llm/llm.py
  • parsed models/moonshot/manifest.yaml and all models/moonshot/models/llm/*.yaml with Ruby YAML
  • local monkeypatch assertion for response_format=json_schema conversion into Moonshot API payload shape

@TuringTzu TuringTzu marked this pull request as ready for review June 12, 2026 05:55
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jun 12, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for the json_schema response format across several Moonshot LLM models by updating their configuration YAML files and modifying the invocation logic in llm.py to parse and format the schema. Feedback was provided to make the JSON schema parsing in llm.py more robust by checking if the schema is already a dictionary before attempting to load it as a string, which prevents potential runtime TypeErrors.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +67 to +70
try:
schema = json.loads(json_schema)
except Exception:
raise ValueError(f"not correct json_schema format: {json_schema}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If json_schema is already passed as a dictionary (which is common in many orchestration frameworks or internal tool calls), calling json.loads() on it will raise a TypeError. To make this more robust, we should check if json_schema is a string before parsing it, and accept it directly if it is already a dictionary.

Suggested change
try:
schema = json.loads(json_schema)
except Exception:
raise ValueError(f"not correct json_schema format: {json_schema}")
if isinstance(json_schema, str):
try:
schema = json.loads(json_schema)
except Exception:
raise ValueError(f"not correct json_schema format: {json_schema}")
elif isinstance(json_schema, dict):
schema = json_schema
else:
raise ValueError("json_schema must be a string or a dictionary")

@dosubot dosubot Bot added the enhancement New feature or request label Jun 12, 2026
@TuringTzu TuringTzu deployed to models/moonshot June 12, 2026 05:56 — with GitHub Actions Active
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants