Skip to content

Conversation

@rkritika1508
Copy link
Collaborator

@rkritika1508 rkritika1508 commented Feb 9, 2026

Summary

Target issue is #14.
Explain the motivation for making this change. What existing problem does the pull request solve?
Fixing three things in this PR, all related to parameter validation and exception handling -

  1. While the post endpoints gives back error for wrong parameter value, it's formatting can be better.
    "error": "Invalid field(s): inputs (Extra inputs are not permitted)"
  2. It also does not give any error for wrong parameter name added with validators.
    "error": "Invalid field(s): validators.0.uli_slur_match.on_pass (Extra inputs are not permitted)"
  3. The error you get for missing input body is not very clear as of now.
    "error": "Missing required field(s): input."

Checklist

Before submitting a pull request, please ensure that you mark these task.

  • Ran fastapi run --reload app/main.py or docker compose up in the repository root and test.
  • If you've fixed a bug or added code that is tested and has test cases.

Notes

Please add here if any other information is required for the reviewer.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced error messaging when validation fails, providing clearer feedback on missing or invalid fields.
    • API now enforces stricter validation, rejecting requests containing unexpected fields for improved data integrity.

@coderabbitai
Copy link

coderabbitai bot commented Feb 9, 2026

📝 Walkthrough

Walkthrough

These changes enhance validation error handling with a new helper function that formats validation errors into readable messages, while standardizing Pydantic model configurations across the codebase using ConfigDict for consistency.

Changes

Cohort / File(s) Summary
Validation Error Formatting
backend/app/core/exception_handlers.py
Introduces _format_validation_errors() helper function to convert RequestValidationError details into human-readable messages. Updates validation_error_handler to use formatted error output with APIResponse.failure_response().
Model Configuration Standardization
backend/app/models/base_validator_config.py, backend/app/models/guardrail_config.py
Adds ConfigDict import from pydantic and updates model configurations. BaseValidatorConfig now uses ConfigDict(extra="forbid", arbitrary_types_allowed=True). GuardrailRequest adds ConfigDict(extra="forbid") to enforce strict field validation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Errors now speak with clarity and grace,
ConfigDicts put each model in its place,
Forbidding extras with a gentle touch,
Validation flows so smoothly—oh, how much!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main changes: it introduces error message formatting improvements and adds stricter parameter validation (extra field forbidding) across multiple handler and model files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/parameter-exception-enhancements

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.

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

🤖 Fix all issues with AI agents
In `@backend/app/core/exception_handlers.py`:
- Around line 11-40: The _format_validation_errors function can return an empty
string when all error entries are filtered out (e.g., top-level loc=("body",)),
producing an empty message; update _format_validation_errors to detect when the
resulting messages list is empty and return a sensible fallback like "Invalid
request body" (or similar) so callers always get a non-empty error message; keep
existing logic (loc filtering, missing_fields, invalid_fields) and only add the
fallback return when messages is empty before returning.
🧹 Nitpick comments (1)
backend/app/core/exception_handlers.py (1)

15-16: Potential KeyError if an error dict lacks "loc" or "msg" keys.

The code accesses err["loc"] (Line 16) and err["msg"] (Line 23) without .get() fallbacks. While Pydantic's RequestValidationError.errors() should always include these keys, defensive access would make this more robust against unexpected error shapes (e.g., from custom validators).

@rkritika1508 rkritika1508 added enhancement New feature or request ready-for-review labels Feb 9, 2026
@rkritika1508 rkritika1508 self-assigned this Feb 9, 2026
@rkritika1508 rkritika1508 linked an issue Feb 9, 2026 that may be closed by this pull request
@rkritika1508 rkritika1508 enabled auto-merge (squash) February 9, 2026 11:50
auto-merge was automatically disabled February 10, 2026 07:06

Pull request was closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request ready-for-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Guardrails: Enhancements on initial code

1 participant