Skip to content

checks: support pydantic-compatible input types#2450

Merged
kevinmessiaen merged 4 commits into
Giskard-AI:mainfrom
harsh21234i:fix/issue-2449-pydantic-input-types
May 14, 2026
Merged

checks: support pydantic-compatible input types#2450
kevinmessiaen merged 4 commits into
Giskard-AI:mainfrom
harsh21234i:fix/issue-2449-pydantic-input-types

Conversation

@harsh21234i
Copy link
Copy Markdown
Contributor

Closes #2449

Summary

  • Broaden _infer_input_type to return Pydantic-compatible annotations beyond BaseModel
  • Relax InputGenerator.__call__ and LLMGeneratorOutput typing for non-BaseModel inputs
  • Validate generator input types with Pydantic TypeAdapter
  • Add tests for list[str], int, dict[str, Any], and MyModel | None

Testing

  • uv run -m pytest -q libs/giskard-checks/tests/core/test_input_type_inference.py libs/giskard-checks/tests/core/ test_input_generator.py libs/giskard-checks/tests/generators/test_llm_generator.py
  • uv run ruff check ...
  • uv run basedpyright ...

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request expands the input type support for generators and interactions beyond BaseModel to include any Pydantic-compatible types, such as list, int, and dict. The changes include updating type hints in InputGenerator, refining the type inference logic in interact.py using TypeAdapter, and making LLMGeneratorOutput generic. Comprehensive tests were added to verify the inference and generation of these new supported types. Feedback was provided regarding a redundant TypeAdapter call in the LLMGenerator implementation that can be removed to simplify the code.

Comment thread libs/giskard-checks/src/giskard/checks/generators/base.py Outdated
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Copy link
Copy Markdown
Member

@kevinmessiaen kevinmessiaen left a comment

Choose a reason for hiding this comment

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

Thanks for your submission, this look great. I have some minor suggestions

Comment thread libs/giskard-checks/src/giskard/checks/core/interaction/interact.py Outdated
Comment thread libs/giskard-checks/src/giskard/checks/core/input_generator.py Outdated
Comment thread libs/giskard-checks/src/giskard/checks/core/input_generator.py Outdated
Comment thread libs/giskard-checks/src/giskard/checks/core/interaction/interact.py
Comment thread libs/giskard-checks/src/giskard/checks/generators/base.py Outdated
Comment thread libs/giskard-checks/tests/core/test_input_generator.py Outdated
Comment thread libs/giskard-checks/tests/core/test_input_generator.py Outdated
Comment thread libs/giskard-checks/tests/core/test_input_type_inference.py Outdated
kevinmessiaen and others added 2 commits May 14, 2026 20:40
- Use type[Any] | None instead of Any | None for input_type parameters
- Improve third overload: type[T] -> AsyncGenerator[T, TraceType] (proper generic)
- Remove str special-case in _infer_input_type; let str pass through so callers can distinguish typed vs untyped
- Catch specific PydanticUserError/TypeError instead of bare except in TypeAdapter guard
- Remove redundant TypeAdapter(T) validation call in BaseLLMGenerator.__call__
- Update tests to match new str-passthrough behavior and add TypeAdapter failure path test

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Return type is type | None (not Any | None), and the docstring now
correctly states str is returned rather than excluded.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@kevinmessiaen kevinmessiaen merged commit 94f671d into Giskard-AI:main May 14, 2026
25 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

feat(giskard-checks): extend input_type support to all pydantic-compatible types

2 participants