{"record":{"id":"5b5c5f5a9c1d65c6","repo":"microsoft/semantic-kernel","slug":"json-helper-requires-a-value-to-be-passed-in","errorCode":null,"errorMessage":"`json` helper requires a value to be passed in.","messagePattern":"`json` helper requires a value to be passed in\\.","errorType":"exception","errorClass":"HandlebarsRuntimeException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Extensions/PromptTemplates.Handlebars/Helpers/KernelHelpers/KernelSystemHelpers.cs","lineNumber":94,"sourceCode":"                name = (string)parameters![\"name\"];\n                value = GetArgumentValue(parameters![\"value\"], variables);\n            }\n            else\n            {\n                var args = ProcessArguments(arguments, variables);\n                name = args[0].ToString() ?? string.Empty;\n                value = args[1];\n            }\n\n            // Set the variable in the Handlebars context\n            variables[name] = value;\n        });\n\n        handlebarsInstance.RegisterHelper(\"json\", (in HelperOptions options, in Context context, in Arguments arguments) =>\n        {\n            if (arguments.Length == 0)\n            {\n                throw new HandlebarsRuntimeException(\"`json` helper requires a value to be passed in.\");\n            }\n\n            var args = ProcessArguments(arguments, variables);\n            object objectToSerialize = args[0];\n\n            object v = objectToSerialize switch\n            {\n                string stringObject => objectToSerialize,\n                _ => JsonSerializer.Serialize(objectToSerialize, s_jsonSerializerOptions)\n            };\n\n            return v;\n        });\n\n        handlebarsInstance.RegisterHelper(\"concat\", (in HelperOptions options, in Context context, in Arguments arguments) =>\n        {\n            var args = ProcessArguments(arguments, variables);\n            return string.Concat(args);","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Extensions/PromptTemplates.Handlebars/Helpers/KernelHelpers/KernelSystemHelpers.cs#L76-L112","documentation":"Thrown by the Handlebars `json` helper when it is invoked with zero arguments (`arguments.Length == 0`). The helper serializes a value to JSON (or passes strings through); with no value to serialize there is nothing meaningful to produce, so it aborts at render time.","triggerScenarios":"Writing `{{json}}` with no argument, or `{{json undefinedVariable}}` where the variable resolved to nothing and was dropped by Handlebars argument binding.","commonSituations":"Forgetting to supply the variable name; referencing a variable that was never added to KernelArguments so it is absent rather than null; copy-pasting a template snippet and leaving the value off.","solutions":["Pass the value explicitly: `{{json myValue}}`.","Confirm the variable is actually populated in KernelArguments before render — absent variables are not passed as arguments.","If the value is optional, guard it with an `{{#if myValue}}...{{json myValue}}...{{/if}}` block."],"exampleFix":"// before\n{{json}}\n// after\n{{json userPreferences}}","handlingStrategy":"validation","validationCode":"// Ensure the variable exists in KernelArguments before render:\nif (!arguments.Contains(\"myValue\")) {\n    throw new InvalidOperationException(\"myValue is required for the json helper.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass a concrete value to {{json}}.","Wrap optional json output in {{#if var}}...{{json var}}...{{/if}}."],"tags":["handlebars","prompt-template","serialization"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}