{"record":{"id":"16b409a6b5a0f289","repo":"kestra-io/kestra","slug":"the-secret-function-expects-an-argument-key","errorCode":null,"errorMessage":"The 'secret' function expects an argument 'key'.","messagePattern":"The 'secret' function expects an argument 'key'\\.","errorType":"exception","errorClass":"PebbleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/functions/SecretFunction.java","lineNumber":142,"sourceCode":"            addSecretConsumer.accept(value);\n        } catch (Exception e) {\n            log.warn(\"Unable to get secret consumer\", e);\n        }\n    }\n\n    @Override\n    public Map<String, String> getArgumentDefaults() {\n        HashMap<String, String> defaults = new HashMap<>();\n        defaults.put(KEY_ARG, \"'MY_SECRET'\");\n        defaults.put(NAMESPACE_ARG, \"flow.namespace\");\n        defaults.put(SUBKEY_ARG, null);\n        defaults.put(FULL_ARG, null);\n        return defaults;\n    }\n\n    protected String getSecretKey(Map<String, Object> args, PebbleTemplate self, int lineNumber) {\n        if (!args.containsKey(KEY_ARG)) {\n            throw new PebbleException(null, \"The 'secret' function expects an argument 'key'.\", lineNumber, self.getName());\n        }\n\n        return (String) args.get(KEY_ARG);\n    }\n}\n","sourceCodeStart":124,"sourceCodeEnd":148,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/functions/SecretFunction.java#L124-L148","documentation":"The secret() function requires a 'key' argument that names the secret to retrieve. The getSecretKey() method checks for the presence of this argument in the args map before proceeding. If the argument is missing entirely (not passed, or passed as null in a way that the key is absent from the map), the function throws immediately.","triggerScenarios":"Calling {{ secret() }} with no arguments. Passing only optional arguments like {{ secret(full=true) }} without the key. A variable that was supposed to provide the key resolves to null or is misspelled so the named argument is absent.","commonSituations":"Misspelling 'key' as 'Key', 'name', or 'secretKey'. A dynamic key expression that evaluates to nothing and the argument is dropped. Refactoring that accidentally removed the key argument.","solutions":["Always pass the key argument first: {{ secret('MY_SECRET') }} or {{ secret(key='MY_SECRET') }}.","Ensure any dynamic expression for the key resolves to a non-null string.","Check for typos in the argument name."],"exampleFix":"# before\n{{ secret() }}\n{{ secret(name='MY_SECRET') }}\n\n# after\n{{ secret('MY_SECRET') }}\n{{ secret(key='MY_SECRET') }}","handlingStrategy":"validation","validationCode":"# Always pass the 'key' argument as the first positional or named argument.\n# Correct: {{ secret('MY_SECRET') }}\n# Correct: {{ secret(key='MY_SECRET') }}\n# Ensure dynamic key expressions resolve to a non-null string:\n{% if inputs.secret_key is not empty %}{{ secret(inputs.secret_key) }}{% else %}MISSING_KEY{% endif %}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always provide the key as the first argument: secret('MY_KEY').","Verify dynamic key expressions resolve to non-null strings.","Check for typos in argument names (it is 'key', not 'name' or 'secretKey')."],"tags":["pebble","secret","arguments","validation","required"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}