Skip to content

feat: Add explicit input validation with clear error messages for model inputs#210

Open
Raakshass wants to merge 2 commits intoopenclimatefix:mainfrom
Raakshass:feat/input-validation
Open

feat: Add explicit input validation with clear error messages for model inputs#210
Raakshass wants to merge 2 commits intoopenclimatefix:mainfrom
Raakshass:feat/input-validation

Conversation

@Raakshass
Copy link

@Raakshass Raakshass commented Feb 2, 2026

Description

Adds explicit input validation with clear error messages for model inputs to address issue #190.

Previously, incorrect input tensor shapes caused cryptic runtime errors. This PR adds fail-fast validation at the API boundary for forward() methods using a new centralized validation utility.

Changes:

  • Add graph_weather/models/validation.py with centralized validation utilities
  • Update GraphWeatherForecaster.forward() to validate input shape
  • Update GraphWeatherAssimilator.forward() to validate input shape
  • Add comprehensive unit tests in tests/test_input_validation.py

Fixes #190

How Has This Been Tested?

Added comprehensive unit tests in tests/test_input_validation.py that verify:

  • Valid 3D tensors pass validation

  • Invalid 2D/1D/4D tensors raise ValueError with clear messages

  • Model imports work correctly

  • Yes

  • Yes (validation logic is pure shape checking, no data processing changes)

Checklist:

  • My code follows OCF's coding style guidelines
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked my code and corrected any misspellings

Raakshass and others added 2 commits February 3, 2026 01:48
…el inputs

Addresses issue openclimatefix#190 - adds fail-fast input validation at the API boundary for model forward() methods.

Changes:

- Add graph_weather/models/validation.py with centralized validation utilities

- Update GraphWeatherForecaster.forward() to validate input shape

- Update GraphWeatherAssimilator.forward() to validate input shape

- Add comprehensive unit tests in tests/test_input_validation.py

Fixes openclimatefix#190
@Raakshass
Copy link
Author

The CI failure is due to pre-existing Ruff linting issues in files I didn't modify (aurora/, cafa/, anemoi_dataloader.py).

My changes to validation.py, forecast.py, analysis.py, and tests/test_input_validation.py are clean and follow the project's coding standards.

Happy to help fix these existing docstring issues in a separate PR if that would be helpful!

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.

Add explicit input validation and clearer error messages for model inputs

1 participant