Skip to content

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

Merged
Pouyanpi merged 4 commits into
developfrom
fix/config-task-prompt
Apr 23, 2025
Merged

fix: use ValueError in TaskPrompt to resolve TypeError raised by Pydantic#1132
Pouyanpi merged 4 commits into
developfrom
fix/config-task-prompt

Conversation

@Pouyanpi

@Pouyanpi Pouyanpi commented Apr 22, 2025

Copy link
Copy Markdown
Collaborator

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 Copilot and tgasser-nv April 22, 2025 07:56
@Pouyanpi Pouyanpi added the bug Something isn't working label Apr 22, 2025

Copilot AI left a comment

Copy link
Copy Markdown

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.

Comment thread tests/rails/llm/test_config.py
@Pouyanpi Pouyanpi self-assigned this Apr 22, 2025

@tgasser-nv tgasser-nv left a comment

Copy link
Copy Markdown
Collaborator

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

3 participants