Skip to content

fix: validate prediction feature dimensions - #19

Merged
CoreyLeath-code merged 3 commits into
mainfrom
fix/validate-predict-feature-dimensions
Aug 9, 2026
Merged

fix: validate prediction feature dimensions#19
CoreyLeath-code merged 3 commits into
mainfrom
fix/validate-predict-feature-dimensions

Conversation

@CoreyLeath-code

@CoreyLeath-code CoreyLeath-code commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Summary

Makes SentinelAI's /predict endpoint enforce the 16-feature input contract of the shipped default SentinelModel. Invalid-width vectors are now rejected by FastAPI/Pydantic validation instead of reaching PyTorch and failing as internal server errors.

Architecture Changes

  • The deployed default MLP has input_dim=16; the public API now exposes that existing constraint at its boundary.
  • This does not add a new model, alter weights, claim model quality, or change valid 16-feature inference behavior.
  • Deployments that deliberately use a differently sized model must update their model artifact and API contract together.

Files Changed

  • api/main.py — defines the 16-feature contract with Pydantic list-length validation.
  • api/core/model.py — corrects the source-level model contract documentation; the previous “arbitrary-length” claim did not match its linear input layer.
  • tests/test_predict.py — verifies one valid 16-element request returns its mocked model result and one 15-element request is rejected with HTTP 422.

Validation Performed

The following workflows completed successfully on this pull request:

Workflow Result Evidence
Continuous Integration & Telemetry Passed run #40: 8 passed, 1 warning
Security Analysis Passed run #38
Ingestion Schema Validation Passed run #75
CodeQL Passed run #57
Performance Benchmarking Passed run #36
Code Quality Assurance Passed run #63
SAST Code Scan Passed run #37

Commands and Real Output

pip install -r requirements-dev.txt
PYTHONPATH=. pytest --cov=. --cov-report=term-missing --cov-report=xml tests/ --junitxml=pytest-results.xml
8 passed, 1 warning in 0.24s
Coverage XML written to file coverage.xml

Risks

  • Clients currently sending a feature vector of any length other than 16 will now receive the explicit HTTP 422 validation response rather than an internal inference error.
  • A non-default model dimension is not auto-discovered; that requires an intentional model/versioning design rather than an inferred fallback.

Follow-up Recommendations

  • Version the feature schema alongside model artifacts before supporting multiple input dimensions.
  • Add representative model-output tests when a trained, versioned artifact and evaluation data are committed.

NEEDS HUMAN DECISION

None.

Summary by CodeRabbit

  • New Features

    • Prediction requests now require exactly 16 numeric features.
    • Added clearer input-field guidance for prediction requests.
  • Bug Fixes

    • Invalid feature vectors are now rejected with a validation error instead of proceeding to inference.
  • Tests

    • Added coverage for valid 16-feature requests and invalid 15-feature requests.

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 26cb362d-93a7-41dc-ad72-6f79ca956dbd

📥 Commits

Reviewing files that changed from the base of the PR and between ff6aa8c and e46d617.

📒 Files selected for processing (3)
  • api/core/model.py
  • api/main.py
  • tests/test_predict.py

📝 Walkthrough

Walkthrough

The API now enforces exactly 16 numeric features for prediction requests. Model documentation describes the fixed-width contract. Tests cover successful inference and rejection of 15-feature vectors.

Changes

Feature Dimension Contract

Layer / File(s) Summary
Define fixed feature dimension
api/core/model.py, api/main.py
The model documentation and request schema define a fixed 16-feature input contract. RequestModel.features uses Pydantic validation and field metadata.
Validate prediction requests
tests/test_predict.py
Prediction tests cover valid 16-feature input and HTTP 422 validation for 15-feature input.

Estimated code review effort: 2 (Simple) | ~10 minutes

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/validate-predict-feature-dimensions

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.

@CoreyLeath-code
CoreyLeath-code marked this pull request as ready for review August 9, 2026 18:30
@CoreyLeath-code
CoreyLeath-code merged commit 8c97571 into main Aug 9, 2026
16 checks passed
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.

1 participant