microsoft/semantic-kernel · error · KernelException

Failed to parse schema.

Error message

Failed to parse schema.

What it means

Thrown by `ExtractNodeInputs` when `JsonNode.Parse` on the JSON-serialized schema string returns null. This is the final step of the YAML->JSON schema conversion; a null parse indicates the intermediate JSON string was empty, null-equivalent, or malformed. It is a KernelException.

Source

Thrown at dotnet/src/Experimental/Process.Core/Workflow/WorkflowBuilder.cs:678

            .FirstOrDefault(node => node["id"]?.ToString() == nodeId);

        if (node is null || !node.Children.TryGetValue("inputs", out YamlNode? inputs) || input is null || inputs is not YamlMappingNode inputMap)
        {
            throw new KernelException("Failed to deserialize workflow.");
        }

        // This dance to convert the YamlMappingNode to a string and then back to a JsonSchema is rather inefficient, need to find a better option.
        // Serialize the YamlMappingNode to a Yaml string
        var serializer = new SerializerBuilder().Build();
        string rawYaml = serializer.Serialize(inputMap);

        // Deserialize the Yaml string to an object
        var deserializer = new DeserializerBuilder().WithNamingConvention(UnderscoredNamingConvention.Instance).Build();
        var yamlObject = deserializer.Deserialize(rawYaml);

        // Serialize the object to a JSON string
        var jsonSchema = JsonSerializer.Serialize(yamlObject);
        var jsonNode = JsonNode.Parse(jsonSchema) ?? throw new KernelException("Failed to parse schema.");

        var inputsDictionary = inputMap.Select(inputMap => new KeyValuePair<string, JsonNode>(inputMap.Key.ToString(), jsonNode))
            .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

        return inputsDictionary;
    }
}

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Ensure input values are non-null and serialize to non-empty JSON.
  2. Inspect `rawYaml` and `jsonSchema` intermediate strings for the offending input to find where the content is lost.
  3. Avoid YAML anchors/aliases or null-only mappings in `inputs`.

Example fix

# before
inputs:
  message: null
# after
inputs:
  message: "hello"
Defensive patterns

Strategy: try-catch

Validate before calling

// Reject inputs whose values are all null before loading.
foreach (var node in workflow.Nodes)
{
    if (node.Inputs is null) continue;
    foreach (var k in node.Inputs.Keys)
    {
        if (node.Inputs[k] is null)
            throw new InvalidOperationException($"Node '{node.Id}' input '{k}' is null; cannot derive schema.");
    }
}

Type guard

bool InputsAreNonNull(Node n) => n.Inputs?.All(kvp => kvp.Value is not null) ?? true;

Try / catch

try { var inputs = builder.ExtractNodeInputs(nodeId); }
catch (KernelException ex) when (ex.Message.Contains("Failed to parse schema"))
{ _logger.LogError(ex, "Schema round-trip produced null JSON for node '{NodeId}'.", nodeId); throw; }

Prevention

When it happens

Trigger: An `inputs` mapping whose serialized form deserializes to an object that re-serializes to an empty/null JSON string; YAML content that collapses to nothing during the serialize/deserialize round-trip (e.g. a mapping containing only null-valued keys).

Common situations: Inputs with all-null values; YAML with anchors/aliases that resolve to empty; library version differences in how empty mappings are serialized; trailing corruption of the schema string.

Understand the failure class

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/3f3762eebbd2147b. Report an issue: GitHub.