Skip to content

feat: Add extraction of default and descriptions for fields in Pydantic models#44

Open
Mahhheshh (Mahhheshh) wants to merge 1 commit intobraintrustdata:mainfrom
Mahhheshh:fix/31
Open

feat: Add extraction of default and descriptions for fields in Pydantic models#44
Mahhheshh (Mahhheshh) wants to merge 1 commit intobraintrustdata:mainfrom
Mahhheshh:fix/31

Conversation

@Mahhheshh
Copy link
Contributor

fixes #31

Adds:

  • test_parameters.py to test_core
  • _extract_pydantic_fields method in py/src/braintrustdata/parameters.py file.

Question:
I should have asked this before; will there be multiple Pydantic fields for a Single Model? How do we need to handle that.

closure:
AI helped me with the tests

Copy link
Member

Choose a reason for hiding this comment

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

a single Pydantic model can have multiple fields. I'm not sure if you should keep metadata per field under schema.properties or flatten into multiple eval params. Can you try both and see what it looks like in the UI?

@AbhiPrasad
Copy link
Member

Also I finally fixed CI for fork PRs. Mind rebasing this PR?

@Mahhheshh Mahhheshh (Mahhheshh) force-pushed the fix/31 branch 3 times, most recently from e5a97bc to 275d3d1 Compare March 6, 2026 17:48
@Mahhheshh
Copy link
Contributor Author

Mahhheshh (Mahhheshh) commented Mar 6, 2026

Apologies for the delay;

The description and defaults are now an array of key-value pairs,
where the key is the field name and the value is the default value/description.

I’m not great at UI, but the frontend could check if it’s a string; if it is, it could display as it did previously. If it's an array, perhaps under the EvalParams, we could have a UL where each field name shows its respective value.

also it would be great to hear from the PM/designers before merging this in.

and; AI helped me with tests

Bonus
image

@Mahhheshh Mahhheshh (Mahhheshh) marked this pull request as ready for review March 8, 2026 17:42
@AbhiPrasad
Copy link
Member

let me do some UI tests with this and adjust stuff accordingly.

raise ValueError(f"Cannot convert {model} to JSON schema - not a pydantic model")


def _extract_pydantic_fields(schema: dict[str, dict[str, Any]]) -> tuple[Any, Any] | tuple[dict[str, Any], dict[str, Any]]:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Returns scalar value if the model has single field, if has multiple fields then flattens the values in dicts.

compatible with validate_parameters()

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.

Python SDK: Parameter descriptions from Pydantic Field not displayed in UI

2 participants