"Cannot be set because it was not declared": ros2 param set and ParameterNotDeclaredException in ROS 2, measured
You ran ros2 param set on a running C++ node and got this:
$ ros2 param set /param_node not_declared 1
Setting parameter failed: parameter 'not_declared' cannot be set because it was not declared
A Python node prints a different line for the same mistake. On Humble it's Setting parameter failed: ('Invalid access to undeclared parameter(s)', []), and on Jazzy and Lyrical it's Setting parameter failed: Invalid access to undeclared parameter(s): []. Inside the node, get_parameter() on a name that was never declared raises ParameterNotDeclaredException in both rclpy and rclcpp.
Short answer: a ROS 2 node only accepts parameters it has declared. Declare the parameter in the node before you set or read it, and give it a default of the type you want:
# rclpy
self.declare_parameter('my_param', 1)
value = self.get_parameter('my_param').value
// rclcpp
this->declare_parameter("my_param", 1);
auto value = this->get_parameter("my_param").as_int();
This also explains parameters that seem to vanish. A value for an undeclared name passed with -p, in a --params-file, or in a launch file's parameters=[...] produced no error and no warning in my runs. The node started normally, the name was missing from ros2 param list, and get_parameter() threw. If your YAML values are ignored but the file parses, check that the node declares those names.
One more thing to know before you script around this: ros2 param set exited with code 0 every time it failed. Check the printed text, not $?.

Find your error text
Every row below comes from the same two nodes (one rclpy, one rclcpp) on Humble, Jazzy and Lyrical. Where the text differs between distros, the row says so.
| What you did | rclcpp node | rclpy node |
|---|---|---|
ros2 param set on an undeclared name |
Setting parameter failed: parameter 'not_declared' cannot be set because it was not declared |
Humble: Setting parameter failed: ('Invalid access to undeclared parameter(s)', [])Jazzy, Lyrical: Setting parameter failed: Invalid access to undeclared parameter(s): [] |
ros2 param set a string on an integer parameter |
Setting parameter failed: Wrong parameter type, parameter {declared_int} is of type {integer}, setting it to {string} is not allowed. |
Humble, Jazzy: Setting parameter failed: Wrong parameter type, expected 'Type.INTEGER' got 'Type.STRING'Lyrical: Setting parameter failed: Wrong parameter type, expected '2' got '4' |
ros2 param set 2.0 on an integer parameter |
same as above, setting it to {double} |
Humble, Jazzy: got 'Type.DOUBLE'Lyrical: expected '2' got '3' |
ros2 param set on a read_only parameter |
Setting parameter failed: parameter 'declared_ro' cannot be set because it is read-only |
Setting parameter failed: Trying to set a read-only parameter: declared_ro. |
ros2 param get on an undeclared name |
Humble, Jazzy: Parameter not set, exit 1Lyrical: Parameter(s) 'not_declared' not available on node, exit 1 |
|
get_parameter() in code on an undeclared name |
rclcpp::exceptions::ParameterNotDeclaredException, message is just the name |
Humble: ParameterNotDeclaredException: ('Invalid access to undeclared parameter(s)', 'undeclared_cli')Jazzy, Lyrical: ParameterNotDeclaredException: Invalid access to undeclared parameter(s): undeclared_cli |
declare_parameter() on a name that was already auto-declared |
rclcpp::exceptions::ParameterAlreadyDeclaredException: parameter 'declared_int' has already been declared |
Humble: ParameterAlreadyDeclaredException: ('Parameter(s) already declared', ['declared_int'])Jazzy, Lyrical: Parameter(s) already declared: ['declared_int'] |
In Lyrical's rclpy messages the types are numbers. They are the ParameterType constants: 2 is integer, 3 is double, 4 is string.
Every failed ros2 param set in the table exited with code 0. The node also logged a warning each time. The C++ node logged [WARN] [rclcpp]: Failed to set parameter: parameter 'not_declared' cannot be set because it was not declared, and the Python node logged the same text as the CLI under its own logger name, [WARN] [param_node]: Failed to set parameter: ....
What I ran
I used the official ros:humble-ros-base, ros:jazzy-ros-base and ros:lyrical-ros-base Docker images, one distro after another. One package held two nodes, a Python script and a C++ executable, both named param_node. Each node declares three integer parameters, all with default 1:
declared_int, a plain declarationdeclared_ro, declared withParameterDescriptor(read_only=True)declared_dyn, declared withParameterDescriptor(dynamic_typing=True)
Then the node calls has_parameter() and get_parameter() on those three plus three names it never declares (undeclared_cli, undeclared_yaml, undeclared_launch), and logs its own parameter list. An environment variable picks the node options: plain, allow_undeclared_parameters=True, automatically_declare_parameters_from_overrides=True, or both. In rclpy these are Node() keyword arguments. In rclcpp they are rclcpp::NodeOptions().allow_undeclared_parameters(true) and .automatically_declare_parameters_from_overrides(true).
For each of the 4 option sets and both languages, I started the node with:
ros2 run pnode py_node.py --ros-args -p undeclared_cli:=1 --params-file all.yaml
where all.yaml is:
/**:
ros__parameters:
declared_int: 5
undeclared_yaml: 2
While the node was running I called ros2 param list, then ros2 param set with an undeclared name, a string and a double on declared_int, a valid integer, a write to the read-only parameter and a string on the dynamic one, then ros2 param get on four names, then ros2 param list again. Separately I started the plain node with five YAML files that differ only in the top-level key or the ros__parameters spelling, once with -p only, and once from a launch file with parameters=[{'declared_int': 7, 'undeclared_launch': 3}].
The behavior was the same on all three distros. Only message wording changed, as shown in the table above.
Undeclared overrides are dropped without a word
With default node options, the node took the values for names it declared and ignored the rest:
| Source | Declared name | Undeclared name |
|---|---|---|
--params-file, key /**: |
declared_int = 5 (default was 1) |
undeclared_yaml: not in the list, get_parameter throws |
-p name:=value |
-p declared_int:=9 gave 9 |
undeclared_cli: not in the list, get_parameter throws |
Launch file parameters=[{...}] |
declared_int = 7 |
undeclared_launch: not in the list, get_parameter throws |
In none of these cases did the node, ros2 run or ros2 launch print a warning about the extra names. The launch output showed process has finished cleanly. From the outside the node looks fine. The value just isn't there.
This is the usual cause behind "my YAML file is found but the parameter isn't loaded". The question on Robotics Stack Exchange with that title has a node that calls get_parameter('variable') without any declare_parameter call. Its YAML key is also mqtt_node while the node is created as mqtt_class, which is a second, separate problem (see below).
The YAML key must match, and typos in ros__parameters fail loudly
I started the plain node with five files. Each file sets declared_int: 5 and undeclared_yaml: 2.
| Top of the file | Result |
|---|---|
/**: then ros__parameters: |
declared_int = 5 |
/param_node: then ros__parameters: |
declared_int = 5 |
/params_node: (wrong name) then ros__parameters: |
no error, exit 0, declared_int = 1 (the default) |
/param_node: then ros_parameters: (one underscore) |
node fails to start |
/param_node: then ros__parameter: (no s) |
node fails to start |
undeclared_yaml was never applied, whatever the key. The two typos stopped the node before any code ran:
[ERROR] [rcl]: Failed to parse global arguments
rclpy._rclpy_pybind11.RCLError: failed to initialize rcl: Couldn't parse params file: '--params-file /y/typo_ros_parameters.yaml'. Error: Cannot have a value before ros__parameters at line 3, at ./src/parse.c:787, at ./src/rcl/arguments.c:406
The Python node exited with code 1. The C++ node threw rclcpp::exceptions::RCLInvalidROSArgsError with the same text, ros2 run printed [ros2run]: Aborted, and the exit code was 250. So a misspelled ros__parameters is not a silent failure. A wrong node name is. For a key that doesn't match, check the name passed to Node(...) (or the name= in your launch file), not the executable or package name. If you aren't sure, /**: matches every node.
The fix options compared
Here is what each option changed, with the same command line and the same YAML file. "List" is the output of ros2 param list /param_node. Every list also had use_sim_time. On Jazzy and Lyrical it had start_type_description_service, and the C++ node also had four qos_overrides./parameter_events.publisher.* entries. I've left those out.
| Default options | allow_undeclared_parameters |
automatically_declare_parameters_from_overrides |
Both | |
|---|---|---|---|---|
| List at startup | 3 declared | 3 declared | 3 declared + undeclared_cli, undeclared_yaml |
3 declared + undeclared_cli, undeclared_yaml |
get_parameter('undeclared_yaml') in code |
throws ParameterNotDeclaredException |
returns type NOT_SET (no value) | returns 2 | returns 2 |
ros2 param get undeclared_yaml |
Parameter not set, exit 1 (Lyrical: not available on node) |
Parameter not set., exit 0 |
Integer value is: 2 |
Integer value is: 2 |
ros2 param set not_declared 1 |
fails | Set parameter successful, name added to the list |
fails with the same error | Set parameter successful |
Your own declare_parameter('declared_int', 1) |
works | works | throws ParameterAlreadyDeclaredException |
throws ParameterAlreadyDeclaredException |
Read the table by row, because each option fixes a different thing.
declare_parameter
This is the standard fix and the only one that keeps type checks and defaults. Declared names got their values from YAML, -p and launch files in every run, and ros2 param set on them worked when the type matched. The parameter shows up in ros2 param list as soon as the node has declared it.
allow_undeclared_parameters=True
It only changes what happens at runtime. ros2 param set on a new name succeeded, and ros2 param get then returned Integer value is: 1. But it did not pick up undeclared names from the YAML file or -p. get_parameter('undeclared_yaml') came back with type NOT_SET, not 2, and the name never appeared in the list. ros2 param get printed Parameter not set., with a period, and exited 0, which differs from the default node's exit 1. If you turned this on to make a YAML value appear and it still doesn't, this is why.
rclcpp issue #851 shows the exact error from ros2 param set /parameter_blackboard foo 1, on a node that was supposed to allow undeclared parameters. That was a 2019 source build, and the thread points to a fix in ros2/demos. On Humble, Jazzy and Lyrical the option did let ros2 param set create new names in both languages.
automatically_declare_parameters_from_overrides=True
This one does the opposite. Every name present in the YAML file or on the command line was declared at startup with the given value, and it showed up in ros2 param list. Setting a brand-new name at runtime still failed with the same "not declared" error. The catch is that your own declare_parameter() for a name that is also in the file now throws ParameterAlreadyDeclaredException. In my nodes that was declared_int. declared_ro and declared_dyn weren't in the file and declared fine. In a real node that exception ends the constructor unless you catch it, or check has_parameter() first.
The launch-file value undeclared_launch was not tested with this option. I only ran the launch case with default options.
Both together
Everything that either option allows worked: overrides were declared, and new names could be set at runtime. It has the same ParameterAlreadyDeclaredException problem. The rclpy question ros2 rclpy list parameters from node uses this combination.
Auto-declared parameters lost type checking in C++
One difference between the languages showed up only with automatically_declare_parameters_from_overrides. In the C++ node, declared_int had been auto-declared from the YAML value 5. After that, ros2 param set /param_node declared_int hello and ros2 param set /param_node declared_int 2.0 both printed Set parameter successful. The Python node, with the same option and the same file, still rejected both with Wrong parameter type. This happened on all three distros. If you rely on type checks for a C++ parameter, declare it yourself rather than letting the override declare it.
Values that come in through launch arguments are strings until something converts them, which is its own source of type surprises: LaunchConfiguration value as int.
read_only and dynamic_typing
A parameter declared with read_only=True got its startup value normally. Writing it with ros2 param set failed with parameter 'declared_ro' cannot be set because it is read-only (C++) or Trying to set a read-only parameter: declared_ro. (Python). That held under every node option, including the C++ auto-declare case above.
A parameter declared with dynamic_typing=True and an integer default accepted ros2 param set /param_node declared_dyn hello, and ros2 param get afterwards printed String value is: hello. Use it when one parameter really needs to hold more than one type. For a plain number, the fix is to pass the right type (3, not 3.0 or "3"). A 2.0 on an integer parameter failed with Wrong parameter type just like a string did.
Version notes
- The rclcpp messages were the same on Humble, Jazzy and Lyrical.
- rclpy on Humble prints exceptions as Python tuples,
('Invalid access to undeclared parameter(s)', []). Jazzy and Lyrical printInvalid access to undeclared parameter(s): []. Search forInvalid access to undeclared parameterand you'll match both. - Lyrical's rclpy prints the wrong-type error with type numbers:
expected '2' got '4'. - Lyrical's
ros2 param geton an undeclared name printsParameter(s) 'not_declared' not available on nodeinstead ofParameter not set. Both exit 1. - Jazzy and Lyrical add
start_type_description_serviceto every node's parameter list. - The parse error for a misspelled
ros__parameterspoints atparse.c:787on Humble,parse.c:800on Jazzy andparse.c:1117on Lyrical. Drop the line numbers when you search. - On Jazzy, 3 of 16
ros2 param listcalls printed the whole list twice. Humble and Lyrical never did it. I didn't look into it further. If you see duplicated entries, don't read them as two parameters.
Not tested
Composable nodes and component containers, ros2 param load and ros2 param dump, the launch file case with allow_undeclared_parameters or auto-declare, namespaced nodes, parameter callbacks (add_on_set_parameters_callback), ros2_control controllers, non-default RMW, and Foxy, Iron and Rolling. The controller question about parameters only known at runtime is about ros2_control's own node options, which I didn't test.
If the node does not start at all and prints "Cannot have a value before ros__parameters", the YAML file itself is malformed; that case and the other params-file parse errors are measured in Failed to parse global arguments: Cannot have a value before ros__parameters.
FAQ
What does "cannot be set because it was not declared" mean?
The C++ node you sent ros2 param set to never declared that parameter, so it refused the value. Add declare_parameter("name", default) in the node, rebuild, and set it again. A Python node gives the same refusal as Invalid access to undeclared parameter(s).
Why do I get ParameterNotDeclaredException even though the YAML file loads?
Loading the file doesn't declare anything. In my runs a YAML value for an undeclared name was dropped without a warning, and get_parameter threw. Call declare_parameter before get_parameter, and the YAML value replaces the default.
Does allow_undeclared_parameters load values from my params file?
No. It let ros2 param set create new names at runtime, but undeclared names from --params-file and -p still came back as NOT_SET. To have file values declared for you, use automatically_declare_parameters_from_overrides=True.
Why does declare_parameter throw ParameterAlreadyDeclaredException?
The node was created with automatically_declare_parameters_from_overrides=True, and the name was in the params file or on the command line, so it was already declared at startup. Check has_parameter() first, or drop the option and declare everything yourself.
Does ros2 param set return a non-zero exit code when it fails?
Not in my runs. Every failure (undeclared name, wrong type, read-only) exited 0 on Humble, Jazzy and Lyrical. Scripts should check for Set parameter successful in the output. ros2 param get on an undeclared name did exit 1.
Measured on 2026-10-30 with ros:humble-ros-base (sha256:d9bcf2e6f72d..., rclpy 3.3.22, rclcpp 16.0.21, ros2param 0.18.20, rcl 5.3.13), ros:jazzy-ros-base (sha256:8eed0a4669bb..., rclpy 7.1.12, rclcpp 28.1.22, ros2param 0.32.13, rcl 9.2.11) and ros:lyrical-ros-base (sha256:3224ee150cb0..., rclpy 10.0.11, rclcpp 32.0.3, ros2param 0.40.9, rcl 10.4.5), default RMW (Fast DDS). Full digests are in digests.txt.
Script and raw output: evidence folder. Questions this answers: parameter_blackboard node parameter cannot be set because it was not declared, Cannot retrieve parameters from YAML file (even if the file is found), use parameters from python launch file in node, ros2 rclpy list parameters from node, How to declare parameter that are only known at runtime.