Skip to content

fix(metrics): handle new Metric types in set_metrics and HTTPValidationError string detail#554

Draft
AnkushMalaker wants to merge 2 commits into
mainfrom
fix/sdk-set-metrics-and-validation-error-parsing
Draft

fix(metrics): handle new Metric types in set_metrics and HTTPValidationError string detail#554
AnkushMalaker wants to merge 2 commits into
mainfrom
fix/sdk-set-metrics-and-validation-error-parsing

Conversation

@AnkushMalaker
Copy link
Copy Markdown
Contributor

@AnkushMalaker AnkushMalaker commented Apr 17, 2026

User description

Summary

  • LogStream.set_metrics() crashes with Metric.get() objects: create_metric_configs checked isinstance against the legacy galileo.schema.metrics.Metric, but Metric.get() returns galileo.metric.Metric subclasses (LlmMetric, CodeMetric). Added a check for the new type, routing by .id when available.
  • HTTPValidationError.from_dict crashes on string detail: The API returns {"detail": "some string"} from GalileoServerException, but the parser iterated detail assuming it was a list of dicts — iterating characters instead. Added a guard for string detail.
  • CodeMetric.create() doesn't handle HTTPValidationError response: Added isinstance check and raises ValidationError with a formatted message (same pattern as jobs.py and experiments.py).

Fixes sc-62865

Test plan

  • LogStream.set_metrics([Metric.get(name="Conciseness")]) no longer raises ValueError
  • CodeMetric(name="existing_name", ...).create() raises ValidationError("already exists") instead of crashing
  • Existing tests pass

Generated description

Below is a concise technical summary of the changes proposed in this PR:
Update create_metric_configs used by LogStream.set_metrics to recognize new galileo.metric.Metric subclasses and route requests by id or name/version. Normalize HTTPValidationError parsing and CodeMetric.create error handling so string detail payloads become ValidationErrors with formatted messages.

TopicDetails
Validation guards Guard HTTPValidationError.from_dict against string detail payloads and have CodeMetric.create raise formatted ValidationErrors when the API responds with validation errors.
Modified files (2)
  • src/galileo/metric.py
  • src/galileo/resources/models/http_validation_error.py
Latest Contributors(2)
UserCommitDate
fernando.correia@galil...chore: update ruff tar...April 07, 2026
thiago.bomfin@galileo.aichore: Migrating remai...March 26, 2026
Metric routing Handle LogStream.set_metrics routes by supporting galileo.metric.Metric instances in create_metric_configs, routing via .id when present and falling back to name/version searches.
Modified files (1)
  • src/galileo/utils/metrics.py
Latest Contributors(2)
UserCommitDate
fernando.correia@galil...chore: update ruff tar...April 07, 2026
quinn-galileofeat!: improve metric ...April 02, 2026
This pull request is reviewed by Baz. Review like a pro on (Baz).

…l in HTTPValidationError

- Add isinstance check for galileo.metric.Metric in create_metric_configs
  so LogStream.set_metrics() works with objects from Metric.get()
- Guard HTTPValidationError.from_dict against string detail from
  GalileoServerException (was iterating characters as dicts)
- Handle HTTPValidationError response in CodeMetric.create() with
  proper error message (same pattern as jobs.py and experiments.py)

sc-62865
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 17, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.52%. Comparing base (2f0db14) to head (53bbc84).

Files with missing lines Patch % Lines
src/galileo/utils/metrics.py 40.00% 3 Missing ⚠️
src/galileo/metric.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #554      +/-   ##
==========================================
- Coverage   82.55%   82.52%   -0.03%     
==========================================
  Files         119      119              
  Lines       10041    10049       +8     
==========================================
+ Hits         8289     8293       +4     
- Misses       1752     1756       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant