[codex] Add Moonshot JSON schema response format#3279
Conversation
There was a problem hiding this comment.
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.
| try: | ||
| schema = json.loads(json_schema) | ||
| except Exception: | ||
| raise ValueError(f"not correct json_schema format: {json_schema}") |
There was a problem hiding this comment.
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.
| 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") |
Summary
json_schemaas a supported Moonshot response format optionjson_schemaparameter on built-in Moonshot/Kimi LLM model schemasresponse_format=json_schemaparameter into Moonshot's structured output request shape0.1.8Why
Moonshot/Kimi's current API supports structured output through
response_format: {"type": "json_schema"}, but the Dify Moonshot plugin only exposedtextandjson_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.pypython -m compileall models/llm/llm.pymodels/moonshot/manifest.yamland allmodels/moonshot/models/llm/*.yamlwith Ruby YAMLresponse_format=json_schemaconversion into Moonshot API payload shape