Skip to content

Add strict unknown-parameter validation mode to notebook execution#869

Open
huyhoang171106 wants to merge 3 commits intonteract:mainfrom
huyhoang171106:feat/add-strict-unknown-parameter-validation-
Open

Add strict unknown-parameter validation mode to notebook execution#869
huyhoang171106 wants to merge 3 commits intonteract:mainfrom
huyhoang171106:feat/add-strict-unknown-parameter-validation-

Conversation

@huyhoang171106
Copy link
Copy Markdown

Summary

Extend execute_notebook(...) with a new boolean argument (default False) that controls behavior when user-supplied parameters are not declared in the notebook’s parameters cell. Today papermill warns for unknown keys; this change should preserve that default but allow strict failure when requested.

Files changed

  • papermill/execute.py (modified)
  • papermill/cli.py (modified)
  • papermill/tests/test_cli.py (modified)

Testing

  • Not run in this environment.

What does this PR do?

Fixes #<issue_number>

Closes #818

Signed-off-by: Nguyen Huy Hoang <181364121+huyhoang171106@users.noreply.github.com>
Signed-off-by: Nguyen Huy Hoang <181364121+huyhoang171106@users.noreply.github.com>
Signed-off-by: Nguyen Huy Hoang <181364121+huyhoang171106@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 26, 2026 14:46
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an opt-in “strict” mode to execute_notebook(...) so callers can fail fast when passing parameters that are not declared in the notebook’s parameters cell (default remains warning-only), addressing #818.

Changes:

  • Extend execute_notebook(...) with a raise_on_unknown_parameters flag and raise on unknown keys when enabled.
  • Add a corresponding CLI flag --raise-on-unknown-parameters/--no-raise-on-unknown-parameters.
  • Add a CLI wiring test to ensure the flag is forwarded to execute_notebook.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
papermill/execute.py Implements strict unknown-parameter validation (raise vs warn).
papermill/cli.py Exposes strict mode via a new Click option and forwards it into execution.
papermill/tests/test_cli.py Adds a CLI test verifying the new option is passed through.
Comments suppressed due to low confidence (1)

papermill/execute.py:22

  • raise_on_unknown_parameters was inserted into the middle of the public execute_notebook signature (between parameters and engine_name). This is a backwards-incompatible API change for any callers that previously passed engine_name (or later args) positionally; those values will now be interpreted as raise_on_unknown_parameters and shift the rest of the arguments. To preserve positional-call compatibility, add the new parameter at the end of the signature (or otherwise avoid shifting existing positional parameters) and update call sites accordingly.
def execute_notebook(
    input_path,
    output_path,
    parameters=None,
    raise_on_unknown_parameters=False,
    engine_name=None,
    request_save_on_cell_execute=True,
    prepare_only=False,
    kernel_name=None,

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread papermill/execute.py
Comment on lines 95 to 105
if parameters:
parameter_predefined = _infer_parameters(nb, name=kernel_name, language=language)
parameter_predefined = {p.name for p in parameter_predefined}
for p in parameters:
if p not in parameter_predefined:
unknown_parameters = [p for p in parameters if p not in parameter_predefined]
if unknown_parameters:
if raise_on_unknown_parameters:
unknown_parameters_message = ", ".join(str(p) for p in sorted(unknown_parameters, key=str))
raise PapermillException(f"Passed unknown parameters: {unknown_parameters_message}")
for p in unknown_parameters:
logger.warning(f"Passed unknown parameter: {p}")
nb = parameterize_notebook(
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new strict-unknown-parameter behavior (raising instead of warning) isn’t covered by unit tests. Since papermill/tests/test_execute.py already exercises execute_notebook, please add tests that (1) verify raise_on_unknown_parameters=True raises for an undeclared key, and (2) verify the default behavior continues to only warn and still parameterizes successfully.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Option to raise exception when unknown parameter passed.

2 participants