ローカルLLMにワークフローを作らせる

This commit is contained in:
Akira
2026-03-02 15:23:50 +09:00
parent e762e230ba
commit 593d13d8a1
14 changed files with 705 additions and 1 deletions

View File

@@ -0,0 +1,57 @@
"""LLM 出力の JSON 構文・スキーマ検証。"""
import json
import jsonschema
# LLM が出力すべき JSON の最小スキーマ
_FLOW_SCHEMA = {
"type": "object",
"required": ["summary", "value"],
"additionalProperties": False,
"properties": {
"summary": {"type": "string", "minLength": 1},
"value": {
"type": "object",
"required": ["modules"],
"properties": {
"modules": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"required": ["id", "value"],
"properties": {
"id": {"type": "string"},
"value": {
"type": "object",
"required": ["type", "language", "content"],
"properties": {
"type": {"type": "string"},
"language": {"type": "string"},
"content": {"type": "string"},
"input_transforms": {"type": "object"},
},
},
},
},
}
},
},
},
}
def validate(raw: str) -> dict:
"""JSON 文字列を構文・スキーマ検証して dict を返す。失敗時は ValueError を投げる。"""
# 構文チェック
try:
data = json.loads(raw)
except json.JSONDecodeError as e:
raise ValueError(f"JSON構文エラー: {e}")
# スキーマチェック
try:
jsonschema.validate(data, _FLOW_SCHEMA)
except jsonschema.ValidationError as e:
raise ValueError(f"JSONスキーマ不正: {e.message}")
return data