Skip to content

fix: custom plot charts function should error on invalid chart types#949

Merged
rapids-bot[bot] merged 2 commits intoNVIDIA:release/1.3from
willkill07:wkk_improve-plot-charts-logic
Oct 8, 2025
Merged

fix: custom plot charts function should error on invalid chart types#949
rapids-bot[bot] merged 2 commits intoNVIDIA:release/1.3from
willkill07:wkk_improve-plot-charts-logic

Conversation

@willkill07
Copy link
Member

@willkill07 willkill07 commented Oct 8, 2025

Description

The original behavior was to fall back to a line chart. Instead, we should raise an error.

Also improves configuration for the example function.

Closes nvbugs-5566144

By Submitting this PR I confirm:

  • I am familiar with the Contributing Guidelines.
  • We require that all contributors "sign-off" on their commits. This certifies that the contribution is your original work, or you have rights to submit it under the same license, or a compatible license.
    • Any contribution which contains commits that are not Signed-Off will not be accepted.
  • When the PR is ready for review, new or existing tests cover these changes.
  • When the PR is ready for review, the documentation is up to date with these changes.

Summary by CodeRabbit

  • New Features

    • Clearer validation and error messages when an unsupported chart type is requested.
    • Configuration options now include descriptive metadata and sensible defaults.
  • Refactor

    • Streamlined chart type resolution with earlier detection and consistent canonical types.
    • Behavior change: invalid chart requests now error out instead of defaulting to a first available type.
  • Bug Fixes

    • Prevents unintended chart selection by enforcing explicit, supported chart types.

@willkill07 willkill07 requested a review from a team as a code owner October 8, 2025 13:23
@coderabbitai
Copy link

coderabbitai bot commented Oct 8, 2025

Walkthrough

Refactors chart type determination to canonical mapping with strict validation and error on unsupported types. Updates workflow config to use Field metadata and LLMRef, and restructures chart creation via a mapping lookup. Resolves chart type before data loading and unifies chart generation logic.

Changes

Cohort / File(s) Summary of Changes
Chart type resolution and validation
examples/custom_functions/plot_charts/src/nat_plot_charts/plot_chat.py
Replaced permissive defaulting with canonical type resolution (line/bar/scatter) and strict validation against available types; raises ValueError on unsupported requests; simplified control flow into a single resolution path.
Workflow config and chart creation refactor
examples/custom_functions/plot_charts/src/nat_plot_charts/register.py
Converted PlotChartsWorkflowConfig fields to use Field with descriptions/defaults; changed llm_name type to LLMRef. Moved chart_type resolution earlier; replaced if/elif chart creation with mapping lookup and added unsupported-type validation; retained error handling.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User
  participant WF as PlotCharts Workflow
  participant DT as determine_chart_type
  participant CG as Chart Generator

  U->>WF: input_message (requested chart type + data refs)
  WF->>DT: resolve chart_type(requested_type, available_types)
  alt supported type
    DT-->>WF: chart_type
    note right of WF: Chart type resolved before data load
    WF->>CG: create_function_mapping[chart_type](data, config)
    CG-->>WF: chart artifact (path/figure)
    WF-->>U: success (description + output file)
  else unsupported type
    DT-->>WF: error (ValueError with original request)
    WF-->>U: error response
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

breaking

Pre-merge checks and finishing touches

Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error)
Check name Status Explanation Resolution
Title Check ❌ Error The title clearly summarizes the fix and is under the 72-character limit, but it uses the phrasing “should error” instead of the imperative form. The style guideline requires titles written as commands in imperative mood. Therefore, it does not fully comply with the title requirements. Please rephrase the title into imperative mood, for example “Fix custom plot charts function to error on invalid chart types.”
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Signed-off-by: Will Killian <wkillian@nvidia.com>
@willkill07 willkill07 force-pushed the wkk_improve-plot-charts-logic branch from 16b2ee0 to 3d9e9cc Compare October 8, 2025 13:25
@willkill07 willkill07 added bug Something isn't working non-breaking Non-breaking change labels Oct 8, 2025
@willkill07 willkill07 self-assigned this Oct 8, 2025
Signed-off-by: Will Killian <wkillian@nvidia.com>
@coderabbitai coderabbitai bot added the breaking Breaking change label Oct 8, 2025
@willkill07 willkill07 removed the breaking Breaking change label Oct 8, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 299561f and f4e3cc8.

📒 Files selected for processing (2)
  • examples/custom_functions/plot_charts/src/nat_plot_charts/plot_chat.py (1 hunks)
  • examples/custom_functions/plot_charts/src/nat_plot_charts/register.py (3 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{py,yaml,yml}

📄 CodeRabbit inference engine (.cursor/rules/nat-test-llm.mdc)

**/*.{py,yaml,yml}: Configure response_seq as a list of strings; values cycle per call, and [] yields an empty string.
Configure delay_ms to inject per-call artificial latency in milliseconds for nat_test_llm.

Files:

  • examples/custom_functions/plot_charts/src/nat_plot_charts/register.py
  • examples/custom_functions/plot_charts/src/nat_plot_charts/plot_chat.py
**/*.py

📄 CodeRabbit inference engine (.cursor/rules/nat-test-llm.mdc)

**/*.py: Programmatic use: create TestLLMConfig(response_seq=[...], delay_ms=...), add with builder.add_llm("", cfg).
When retrieving the test LLM wrapper, use builder.get_llm(name, wrapper_type=LLMFrameworkEnum.) and call the framework’s method (e.g., ainvoke, achat, call).

**/*.py: In code comments/identifiers use NAT abbreviations as specified: nat for API namespace/CLI, nvidia-nat for package name, NAT for env var prefixes; do not use these abbreviations in documentation
Follow PEP 20 and PEP 8; run yapf with column_limit=120; use 4-space indentation; end files with a single trailing newline
Run ruff check --fix as linter (not formatter) using pyproject.toml config; fix warnings unless explicitly ignored
Respect naming: snake_case for functions/variables, PascalCase for classes, UPPER_CASE for constants
Treat pyright warnings as errors during development
Exception handling: use bare raise to re-raise; log with logger.error() when re-raising to avoid duplicate stack traces; use logger.exception() when catching without re-raising
Provide Google-style docstrings for every public module, class, function, and CLI command; first line concise and ending with a period; surround code entities with backticks
Validate and sanitize all user input, especially in web or CLI interfaces
Prefer httpx with SSL verification enabled by default and follow OWASP Top-10 recommendations
Use async/await for I/O-bound work; profile CPU-heavy paths with cProfile or mprof before optimizing; cache expensive computations with functools.lru_cache or external cache; leverage NumPy vectorized operations when beneficial

Files:

  • examples/custom_functions/plot_charts/src/nat_plot_charts/register.py
  • examples/custom_functions/plot_charts/src/nat_plot_charts/plot_chat.py
**/*

⚙️ CodeRabbit configuration file

**/*: # Code Review Instructions

  • Ensure the code follows best practices and coding standards. - For Python code, follow
    PEP 20 and
    PEP 8 for style guidelines.
  • Check for security vulnerabilities and potential issues. - Python methods should use type hints for all parameters and return values.
    Example:
    def my_function(param1: int, param2: str) -> bool:
        pass
  • For Python exception handling, ensure proper stack trace preservation:
    • When re-raising exceptions: use bare raise statements to maintain the original stack trace,
      and use logger.error() (not logger.exception()) to avoid duplicate stack trace output.
    • When catching and logging exceptions without re-raising: always use logger.exception()
      to capture the full stack trace information.

Documentation Review Instructions - Verify that documentation and comments are clear and comprehensive. - Verify that the documentation doesn't contain any TODOs, FIXMEs or placeholder text like "lorem ipsum". - Verify that the documentation doesn't contain any offensive or outdated terms. - Verify that documentation and comments are free of spelling mistakes, ensure the documentation doesn't contain any

words listed in the ci/vale/styles/config/vocabularies/nat/reject.txt file, words that might appear to be
spelling mistakes but are listed in the ci/vale/styles/config/vocabularies/nat/accept.txt file are OK.

Misc. - All code (except .mdc files that contain Cursor rules) should be licensed under the Apache License 2.0,

and should contain an Apache License 2.0 header comment at the top of each file.

  • Confirm that copyright years are up-to date whenever a file is changed.

Files:

  • examples/custom_functions/plot_charts/src/nat_plot_charts/register.py
  • examples/custom_functions/plot_charts/src/nat_plot_charts/plot_chat.py
examples/**/*

⚙️ CodeRabbit configuration file

examples/**/*: - This directory contains example code and usage scenarios for the toolkit, at a minimum an example should
contain a README.md or file README.ipynb.

  • If an example contains Python code, it should be placed in a subdirectory named src/ and should
    contain a pyproject.toml file. Optionally, it might also contain scripts in a scripts/ directory.
  • If an example contains YAML files, they should be placed in a subdirectory named configs/. - If an example contains sample data files, they should be placed in a subdirectory named data/, and should
    be checked into git-lfs.

Files:

  • examples/custom_functions/plot_charts/src/nat_plot_charts/register.py
  • examples/custom_functions/plot_charts/src/nat_plot_charts/plot_chat.py
🧬 Code graph analysis (1)
examples/custom_functions/plot_charts/src/nat_plot_charts/register.py (3)
src/nat/data_models/component_ref.py (1)
  • LLMRef (116-124)
src/nat/data_models/function.py (1)
  • FunctionBaseConfig (26-27)
examples/custom_functions/plot_charts/src/nat_plot_charts/plot_chat.py (4)
  • determine_chart_type (153-169)
  • create_line_plot (60-82)
  • create_bar_plot (85-118)
  • create_scatter_plot (121-150)
🪛 Ruff (0.13.3)
examples/custom_functions/plot_charts/src/nat_plot_charts/plot_chat.py

169-169: Avoid specifying long messages outside the exception class

(TRY003)

@willkill07
Copy link
Member Author

/merge

@rapids-bot rapids-bot bot merged commit fc2903b into NVIDIA:release/1.3 Oct 8, 2025
17 checks passed
@willkill07 willkill07 deleted the wkk_improve-plot-charts-logic branch October 23, 2025 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants