Skip to content

fix: use ValueError in TaskPrompt to resolve TypeError raised by Pydantic #1132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 23, 2025

Conversation

Pouyanpi
Copy link
Collaborator

@Pouyanpi Pouyanpi commented Apr 22, 2025

Description

Replaced the use of Pydantic's ValidationError with ValueError in the TaskPrompt class's root_validator. This resolves a TypeError caused by incorrect instantiation of ValidationError during validation.

  • Added Tests

related to #1111

@Pouyanpi Pouyanpi added this to the v0.14.0 milestone Apr 22, 2025
@Pouyanpi Pouyanpi requested review from tgasser-nv and Copilot April 22, 2025 07:56
@Pouyanpi Pouyanpi added the bug Something isn't working label Apr 22, 2025
Copy link

@Copilot 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

This PR replaces the use of Pydantic’s ValidationError with ValueError in the TaskPrompt root_validator to resolve a previously raised TypeError during validation.

  • Switch exception type in TaskPrompt from ValidationError to ValueError.
  • Add tests to verify TaskPrompt validation logic.

Reviewed Changes

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

File Description
tests/rails/llm/test_config.py Tests for TaskPrompt now expect a validation error; however, the exception type in the PR has changed.
nemoguardrails/rails/llm/config.py Updated TaskPrompt.check_fields to raise ValueError instead of ValidationError.

@Pouyanpi Pouyanpi self-assigned this Apr 22, 2025
Copy link
Collaborator

@tgasser-nv tgasser-nv left a comment

Choose a reason for hiding this comment

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

LGTM thanks for adding the tests

Added `ge=1` validation to `max_length` and `max_tokens` fields in the
TaskPrompt class to ensure values are greater than or equal to 1.
Replaced the use of Pydantic's ValidationError with ValueError in the
TaskPrompt class's root_validator. This resolves a TypeError caused by
incorrect instantiation of ValidationError during validation.
@Pouyanpi Pouyanpi force-pushed the fix/config-task-prompt branch from 33ff9f7 to 81236d6 Compare April 23, 2025 07:27
@Pouyanpi Pouyanpi merged commit 6540bb5 into develop Apr 23, 2025
10 checks passed
@Pouyanpi Pouyanpi deleted the fix/config-task-prompt branch April 23, 2025 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants