Skip to content

Build AI methods with your coding agent, then run them anywhere: as an MCP for chatbots, as a webapp for people, or via API for your software.

feature/Rating-label · L-261009-ece0f5 (#1401)

Louis Choquel89b67f833a99
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c900b46c6..7a4599a90 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,10 +4,12 @@
### Added
+- **`Rating` carries the label of its level**: the `Rating` native has an optional `label`, which the MTHDS standard's native set pinned at `5.0.0` defines as the name of the selected level when the scale declares labels, held in `RatingContent.label` and stated by the input-form descriptor, the I/O contracts and the generated Python and TypeScript types. A `PipeJudge` declares no labelled levels yet, so a `Rating` it produces carries no label, while a `PipeLLM` whose output is `Rating`, or any other producer, may fill it like any optional member; either way a `Rating` renders in a prompt as its label when it has one and as its level otherwise, so `$severity` reads `Workaround available` for a rating carrying that label and `1` for one carrying none, and its JSON rendering carries the label only when present. Since a crate materializes the pinned definition, a crate whose methods use `Rating` gets a new normalized fingerprint, and types generated before this release gain the field when `pipelex codegen types` regenerates them.
- **A log line's advice in `user_action`**: a log call puts what its reader should do in a `user_action` field, one imperative sentence, and the `console` sink prints it whole on a line of its own under the record, after `→ `, in cyan, while every other sink writes it as a field like any other. Pipelex's own warnings carry their advice there, such as `Run pipelex migrate to update it` on a stale configuration file, so their message says only what happened.
### Changed
+- **MTHDS standard 5.0.0 (Breaking)**: pipelex now requires `mthds==0.21.0` and `pipelex-sdk==0.38.0`, the releases that report MTHDS standard `5.0.0`, so everyone downstream inherits those exact versions and a project that pins either package itself has to move with them. `pipelex --version` prints `mthds-standard 5.0.0`, every crate pipelex normalizes is stamped with `mthds_version` `5.0.0` and materializes the native set the standard pinned at `5.0.0`, and a package whose `METHODS.toml` constrains `mthds_version` to `^4.0.0`, `~4.0.0`, `4.*` or exactly `4.0.0` now logs a warning when it loads, which `>=4.0.0` or `^5.0.0` does not. `PipeJudge` keeps the fields its page documents, without the evidence `prompt`, the `questions` and the two-sided criteria the standard's `5.0.0` PipeJudge defines.
- **Console lines without the emoji prefix or the path column (Breaking)**: a line logged under the `pipelex` package or a `pipelex_` one, the runtime's, the API server's or a plugin's named that way, and a line logged on the root logger start with their message, and a line another library logged starts with that library's top-level package name, dimmed, such as `httpx: `, where every line used to start with an emoji or a bracketed logger name. The column naming the source file and line of each record is off by default; set `is_show_path = true` under `[runtime.log.rich_log]` to show it, `is_link_path_enabled` still making it clickable. The `pipelex.tools.log.log_formatter` module is gone with its `EmojiLogFormatter`, so code that formatted records with it uses the stdlib's `logging.Formatter`.
- **Log messages are one short sentence (Breaking)**: Pipelex's log messages, and its API server's, say what happened in one sentence that starts with a capital and ends with no period, and at `INFO` and above hold no identifier and no backtick in at most 80 characters, the advice they used to append now riding `user_action`. Warnings about one event became one: whichever kind of inference job carried no usage, the line is `An inference job reported no usage` with `inference_job_type`; a stale configuration file is `A configuration file is out of date and was migrated in memory only` whatever its remedy; and a `PipeBatch` over a large list is `A PipeBatch fans out over a large list without durable execution`, bounded or not, with `max_concurrency` absent when the fan-out is unbounded. What breaks is a log query or an alert written against an old message.
- **The API server's refusals of a caller's credentials log at `DEBUG` (Breaking)**: a request with no bearer token, an expired or invalid token or a wrong API key logs `A caller's credentials were refused` at `DEBUG`, with `auth_mode` and `auth_refusal_reason` (`missing_bearer_token`, `expired_token`, `invalid_token` or `api_key_mismatch`), since the error line the server writes at `WARNING` for every `401` already records the refusal. A token that verifies but whose `user_id` claim is missing, not a path-safe segment or the reserved single-tenant id still logs at `WARNING`, its `user_action` telling the token issuer what to fix, and an unset `JWT_SECRET_KEY` or `API_KEY` logs at `ERROR` with the variable's name in `env_var`. An alert on the old authentication warnings counts the `401` error lines instead.
diff --git a/docs/building-methods/concepts/native-concepts.md b/docs/building-methods/concepts/native-concepts.md
index bbaf511bb..8f7f95ac2 100644
--- a/docs/building-methods/concepts/native-concepts.md
+++ b/docs/building-methods/concepts/native-concepts.md
@@ -258,12 +258,15 @@ class ChoiceContent(StuffContent):
class RatingContent(StuffContent):
level: int # the index of the selected level, 0 being the first
+ label: str | None = None # the selected level's label, when the scale declares labels
confidence: float | None = None # from 0 to 1
probabilities: dict[str, float] | None = None # keyed by level index written as text: "0", "1", ...
position: float | None = None # a continuous position, from 0 to the last level's index
```
-A `Choice` renders as its key and a `Rating` as its level, so `$team` in a later prompt reads `billing` and `$severity` reads `2`. Branch on them with a `PipeCondition`: `expression = "team.choice"` routes by the key, and `expression = "'severe' if severity.level >= 2 else 'mild'"` by the level.
+A `Rating`'s `label` is not a measure. The MTHDS standard defines it as the name of the selected level, when the scale declares labels. A `PipeJudge` declares no labelled levels yet, so a `Rating` it produces carries no `label`; a `PipeLLM` whose output is `Rating`, or any other producer, may fill it like any optional member. The `level` stays the verdict either way.
+
+A `Choice` renders as its key, and a `Rating` as its label when it has one and as its level otherwise, so `$team` in a later prompt reads `billing`, and `$severity` reads `Workaround available` for a rating carrying that label and `1` for one carrying none. Branch on them with a `PipeCondition`: `expression = "team.choice"` routes by the key, and `expression = "'severe' if severity.level >= 2 else 'mild'"` by the level, which every `Rating` has, labelled or not.
A measure is only as good as its producer. A language model asked to fill a verdict — a `PipeLLM` whose output is `YesNo`, `Choice` or `Rating` — sees the uncertainty members, optional and described, and may fill them with its own estimate of its verdict. That estimate is worth having, and it is not the probability a dedicated judging model measures over the options it was given: a `Choice` written by a `PipeLLM` has no declared option set behind it, so its `probabilities` are keyed by whatever the model wrote. When a `PipeCondition` gates on a probability, read which producer wrote it, and guard against its absence: `approved.probability is not none and approved.probability >= 0.8`.
diff --git a/pipelex/core/concepts/native/pinned_blueprints.py b/pipelex/core/concepts/native/pinned_blueprints.py
index 4bb7e68e4..b3c073471 100644
--- a/pipelex/core/concepts/native/pinned_blueprints.py
+++ b/pipelex/core/concepts/native/pinned_blueprints.py
@@ -14,7 +14,7 @@ standard's page itself, read live from the sibling `mthds/` checkout (the `MTHDS
conformance` CI workflow runs it against a fresh checkout on every pull request), so the day the
standard moves a definition, this repo goes red instead of a downstream port.
-The set below is the one the standard pinned at MTHDS 3.0.0, named by
+The set below is the one the standard pinned at MTHDS 5.0.0, named by
`PINNED_NATIVES_MTHDS_VERSION`. Version-keyed lookup can come when a second pinned set exists;
until then an implementation of standard version `V` materializes the greatest pinned set not
above `V`, and this is the only one there is.
@@ -32,7 +32,7 @@ from pipelex.core.concepts.native.concept_native import NativeConceptCode
# is the latest release of the standard. `tests/unit/pipelex/core/concepts/test_pinned_natives_vs_standard.py`
# holds this value to the page; `test_pinned_natives_version.py` beside it holds it to the standard
# version this engine implements, which is the reading that needs no sibling checkout.
-PINNED_NATIVES_MTHDS_VERSION = "3.0.0"
+PINNED_NATIVES_MTHDS_VERSION = "5.0.0"
def make_pinned_native_blueprint(native_code: NativeConceptCode) -> ConceptBlueprint:
@@ -172,6 +172,7 @@ def _pinned_structure(native_code: NativeConceptCode) -> dict[str, ConceptStruct
type=ConceptStructureBlueprintFieldType.INTEGER,
required=True,
),
+ "label": _text_field(description="The label of the selected level, when the scale declares labels."),
"confidence": _number_field(description="The producer's confidence in the level, from 0 to 1, when it reports one."),
"probabilities": _number_dict_field(
description="The probability of each level, keyed by level index written as text, when the producer measures a distribution.",
diff --git a/pipelex/core/stuffs/rating_content.py b/pipelex/core/stuffs/rating_content.py
index a5e5cef07..7972d1d49 100644
--- a/pipelex/core/stuffs/rating_content.py
+++ b/pipelex/core/stuffs/rating_content.py
@@ -1,3 +1,4 @@
+import html
import json
from pydantic import Field
@@ -12,6 +13,9 @@ class RatingContent(StuffContent):
# strict=True for the same reason as `YesNoContent.yes_no`: lax mode would turn "2" or 2.0 into a level.
level: int = Field(ge=0, description="The index of the selected level, 0 being the first level declared.", strict=True)
+ # Not a measure: the name the scale's declaration gives the selected level, copied from it, so a reader sees the
+ # name rather than the index. The level stays the verdict a method branches on.
+ label: str | None = Field(default=None, description="The label of the selected level, when the scale declares labels.")
confidence: float | None = Field(
default=None, ge=0, le=1, strict=True, description="The producer's confidence in the level, from 0 to 1, when it reports one."
)
@@ -32,17 +36,24 @@ class RatingContent(StuffContent):
def short_desc(self) -> str:
return f"a rating (level {self.level})"
+ def _verdict_text(self) -> str:
+ """The verdict as a reader reads it: the level's label when the scale named it, its index otherwise.
+
+ An empty label names nothing, so it falls back to the index too, rather than rendering the rating as nothing.
+ """
+ return self.label or str(self.level)
+
@override
def rendered_plain(self) -> str:
- return str(self.level)
+ return self._verdict_text()
@override
def rendered_html(self) -> str:
- return str(self.level)
+ return html.escape(self._verdict_text())
@override
def rendered_markdown(self, *, level: int = 1, is_pretty: bool = False) -> str:
- return str(self.level)
+ return self._verdict_text()
@override
def rendered_json(self) -> str:
diff --git a/pyproject.toml b/pyproject.toml
index 62d09c572..bcdbe7aeb 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -31,7 +31,7 @@ dependencies = [
"json2html>=1.3.0",
"kajson==0.7.1",
"markdown-it-py[linkify]>=3.0.0", # the Markdown concept, the `markdown` filter and the built-in PDF engine
- "mthds==0.20.0",
+ "mthds==0.21.0",
"networkx>=3.4.2",
"openai>=2.0.0",
"opentelemetry-api>=1.39.0",
@@ -43,7 +43,7 @@ dependencies = [
# The client for the hosted Pipelex API, behind hosted runs (pipelex/hosted/). Pinned exactly, like
# mthds: each pipelex-sdk release pins mthds exactly too, so the release chosen here must pin the
# same mthds as this file, and the two pins move together (the bump-mthds skill says so).
- "pipelex-sdk==0.37.0",
+ "pipelex-sdk==0.38.0",
"polyfactory>=2.21.0",
"portkey-ai>=2.1.0",
"posthog>=6.7.0",
diff --git a/tests/integration/pipelex/pipeline/test_input_form_verdict_natives.py b/tests/integration/pipelex/pipeline/test_input_form_verdict_natives.py
index adf0f100d..8dcdd6945 100644
--- a/tests/integration/pipelex/pipeline/test_input_form_verdict_natives.py
+++ b/tests/integration/pipelex/pipeline/test_input_form_verdict_natives.py
@@ -1,6 +1,6 @@
"""`YesNo` is read by position: a `boolean` where a caller supplies it, an `object` where a producer reports it.
-`Choice` and `Rating` are objects on both sides, with their pinned fields. The position is set once by
+`Choice` and `Rating` are objects on both sides, with their pinned fields, `Rating`'s `label` among them. The position is set once by
`build_input_form` and `build_output_form` and read in `YesNo`'s row alone, so these tests reach a
`YesNo` at every depth on each side: at the top, as a list's item, as a nested structure field, through
a refinement, and through a reflected class field.
@@ -207,8 +207,10 @@ class TestVerdictNativesByPosition:
for grade in (_field_by_name(verdicts, "grade"), output_form["verdict_forms.rating_out"].field):
assert grade.kind == FieldKind.OBJECT
grade_fields = fields_by_name(grade)
- assert list(grade_fields) == ["level", "confidence", "probabilities", "position"], "Pinned-blueprint fields, in pinned order"
+ assert list(grade_fields) == ["level", "label", "confidence", "probabilities", "position"], "Pinned-blueprint fields, in pinned order"
assert grade_fields["level"].kind == FieldKind.NUMBER
assert grade_fields["level"].integer is True
assert grade_fields["level"].required is True
+ assert grade_fields["label"].kind == FieldKind.TEXT
+ assert grade_fields["label"].required is False
assert grade_fields["position"].required is False
diff --git a/tests/unit/pipelex/cli/dev_cli/test_projection_reference.py b/tests/unit/pipelex/cli/dev_cli/test_projection_reference.py
index 5a1550c8c..b2a38ed56 100644
--- a/tests/unit/pipelex/cli/dev_cli/test_projection_reference.py
+++ b/tests/unit/pipelex/cli/dev_cli/test_projection_reference.py
@@ -232,9 +232,10 @@ class TestOutOfMatrixNatives:
"native.Rating",
[
{"kind": "number", "name": "level", "required": True, "integer": True},
+ {"kind": "text", "name": "label", "required": False},
{"kind": "number", "name": "position", "required": False, "integer": False},
],
- {"level": 0, "position": 0.0},
+ {"level": 0, "label": "label_value", "position": 0.0},
),
],
)
diff --git a/tests/unit/pipelex/codegen/test_rating_projection.py b/tests/unit/pipelex/codegen/test_rating_projection.py
new file mode 100644
index 000000000..6d151b3f3
--- /dev/null
+++ b/tests/unit/pipelex/codegen/test_rating_projection.py
@@ -0,0 +1,125 @@
+"""A method whose output is `Rating`: the generated Python and TypeScript carry the level's `label`.
+
+Codegen never reads the runtime content class: normalization materializes the pinned `native.Rating`
+into the crate, and every emitter projects that definition. So the member the standard re-pinned at
+MTHDS 5.0.0 reaches a consumer's types through the pinned set alone, and this module holds the
+projections to it from an authored method, the way a consumer's `pipelex codegen` reaches them:
+`python-pydantic` and `ts-zod` emit the native as a model of its own, and `python-structures` points
+at the runtime `RatingContent`, which carries the member itself.
+"""
+
+import json
+import subprocess # ruff: ignore[suspicious-subprocess-import]
+from pathlib import Path
+from typing import Any
+
+from pipelex.codegen.emitters.python_pydantic import emit_python_pydantic
+from pipelex.codegen.emitters.python_structures import emit_python_structures
+from pipelex.codegen.emitters.ts_zod import emit_ts_zod
+from pipelex.codegen.resolved_concepts import ResolvedLibrary, resolve_concepts_from_crate
+from pipelex.core.stuffs.rating_content import RatingContent
+from pipelex.libraries.crate_normalization import normalize_crate
+from pipelex.libraries.library_crate_factory import LibraryCrateFactory
+from pipelex.mthds_parsing.parser import MthdsParser
+from tests.helpers.ts_toolchain import resolve_node, resolve_zod_package
+from tests.unit.pipelex.codegen.conftest import CRATE_TEST_VERSION, load_generated_module
+
+_RATING_METHOD_MTHDS = """
+domain = "triage"
+description = "Rates how severe a reported issue is"
+
+[concept.Assessment]
+description = "An assessment holding a rating as a field"
+
+[concept.Assessment.structure]
+severity = { type = "concept", concept_ref = "native.Rating", description = "How severe the issue is", required = true }
+
+[pipe.rate_severity]
+type = "PipeLLM"
+description = "Rates how severe a reported issue is"
+inputs = { report = "Text" }
+output = "Rating"
+prompt = "How severe is this issue? $report"
+
+[pipe.assess]
+type = "PipeLLM"
+description = "Assesses a reported issue"
+inputs = { report = "Text" }
+output = "Assessment"
+prompt = "Assess this issue. $report"
+"""
+
+
+def _resolved_rating_method() -> ResolvedLibrary:
+ blueprint = MthdsParser.make_pipelex_bundle_blueprint(mthds_content=_RATING_METHOD_MTHDS)
+ crate = LibraryCrateFactory.make_from_blueprints(blueprints=[blueprint])
+ return resolve_concepts_from_crate(normalize_crate(crate, mthds_version=CRATE_TEST_VERSION))
+
+
+class TestRatingProjection:
+ def test_the_crate_materializes_the_rating_with_its_label(self):
+ resolved = _resolved_rating_method()
+ rating = resolved.by_ref().get("native.Rating")
+ assert rating is not None, "a method whose output is Rating must materialize native.Rating into its crate"
+ assert [field.name for field in rating.fields] == ["level", "label", "confidence", "probabilities", "position"]
+
+ def test_python_pydantic_carries_the_label(self, tmp_path: Path):
+ content = emit_python_pydantic(_resolved_rating_method())[0].content
+ assert "class Rating(BaseModel):" in content
+ assert "label: str | None" in content
+ module = load_generated_module(content, tmp_path=tmp_path, name="gen_models_rating")
+ rating = module.Rating(level=1, label="Workaround available")
+ assert module.Rating.model_validate(rating.model_dump(mode="json")) == rating
+ # The runtime's own transport dump of a labelled rating validates against the generated model.
+ wire = RatingContent(level=1, label="Workaround available", confidence=0.6).smart_dump()
+ assert module.Rating.model_validate(wire).label == "Workaround available"
+
+ def test_python_structures_points_at_the_runtime_class_that_carries_the_label(self):
+ content = emit_python_structures(_resolved_rating_method())[0].content
+ assert "severity: RatingContent" in content
+ assert "label" in RatingContent.model_fields
+
+ def test_ts_zod_carries_the_label(self):
+ content = emit_ts_zod(_resolved_rating_method())[0].content
+ assert "export const RatingSchema = z.object({" in content
+ assert "label: z.string().nullish()," in content
+
+ def test_the_emitted_schema_parses_the_runtime_payload(self, tmp_path: Path):
+ """A real zod, the emitted schema, the runtime's own JSON for a labelled and an unlabelled rating.
+
+ Mandatory under `make test-ts-gates`, as every TypeScript gate is; opportunistic elsewhere, where the
+ two pins above hold the line.
+ """
+ node = resolve_node()
+ zod_package = resolve_zod_package()
+
+ content = emit_ts_zod(_resolved_rating_method())[0].content
+ wire_payloads: list[dict[str, Any]] = [
+ RatingContent(level=1, label="Workaround available", confidence=0.6).smart_dump(),
+ RatingContent(level=2).smart_dump(),
+ ]
+ (tmp_path / "types.ts").write_text(content, encoding="utf-8")
+ (tmp_path / "package.json").write_text('{ "type": "module" }\n', encoding="utf-8")
+ (tmp_path / "node_modules").mkdir()
+ (tmp_path / "node_modules" / "zod").symlink_to(zod_package, target_is_directory=True)
+ (tmp_path / "wire.json").write_text(json.dumps(wire_payloads), encoding="utf-8")
+ (tmp_path / "driver.ts").write_text(
+ 'import { readFileSync } from "node:fs";\n'
+ 'import { RatingSchema } from "./types.ts";\n'
+ 'const wire = JSON.parse(readFileSync("wire.json", "utf-8"));\n'
+ "process.stdout.write(JSON.stringify(wire.map((one: unknown) => RatingSchema.parse(one))));\n",
+ encoding="utf-8",
+ )
+
+ run = subprocess.run( # ruff: ignore[subprocess-without-shell-equals-true]
+ [node, "--experimental-strip-types", "--no-warnings", "driver.ts"],
+ cwd=tmp_path,
+ capture_output=True,
+ text=True,
+ check=False,
+ )
+ assert run.returncode == 0, f"the emitted schema rejected the runtime's own payload:\n{run.stdout}\n{run.stderr}"
+
+ labelled, unlabelled = json.loads(run.stdout)
+ assert labelled["label"] == "Workaround available"
+ assert unlabelled["label"] is None
diff --git a/tests/unit/pipelex/core/stuffs/verdict_content/test_rating_content.py b/tests/unit/pipelex/core/stuffs/verdict_content/test_rating_content.py
index babc39c55..77f4948e1 100644
--- a/tests/unit/pipelex/core/stuffs/verdict_content/test_rating_content.py
+++ b/tests/unit/pipelex/core/stuffs/verdict_content/test_rating_content.py
@@ -4,10 +4,11 @@ import pytest
from pydantic import ValidationError
from pipelex.core.stuffs.rating_content import RatingContent
+from pipelex.tools.templating.text_format import TextFormat
class TestRatingContent:
- """`Rating` requires its level index; `confidence`, `probabilities` and `position` are optional measures."""
+ """`Rating` requires its level index; `label` names the selected level, and `confidence`, `probabilities` and `position` are optional measures."""
def test_requires_the_level(self):
with pytest.raises(ValidationError, match="level"):
@@ -15,6 +16,7 @@ class TestRatingContent:
def test_measures_are_absent_by_default(self):
content = RatingContent(level=2)
+ assert content.label is None
assert content.confidence is None
assert content.probabilities is None
assert content.position is None
@@ -25,6 +27,16 @@ class TestRatingContent:
assert content.position == 1.2
assert content.probabilities == {"0": 0.1, "1": 0.6, "2": 0.3}
+ def test_accepts_the_label_of_the_selected_level(self):
+ content = RatingContent(level=1, label="Workaround available")
+ assert content.level == 1
+ assert content.label == "Workaround available"
+
+ @pytest.mark.parametrize("label", [1, 1.5, True, ["Cosmetic"]])
+ def test_refuses_a_label_that_is_not_a_text(self, label: object):
+ with pytest.raises(ValidationError, match="label"):
+ RatingContent.model_validate({"level": 1, "label": label})
+
def test_refuses_a_negative_level(self):
with pytest.raises(ValidationError, match="level"):
RatingContent(level=-1)
@@ -42,19 +54,72 @@ class TestRatingContent:
with pytest.raises(ValidationError, match="probabilities"):
RatingContent(level=0, probabilities={"0": 1.2})
- def test_renders_as_its_level(self):
+ def test_renders_as_its_level_without_a_label(self):
content = RatingContent(level=3, position=2.7)
assert content.rendered_plain() == "3"
assert content.rendered_markdown() == "3"
assert content.rendered_html() == "3"
assert content.rendered_for_prompt() == "3"
+ assert content.rendered_for_prompt(text_format=TextFormat.MARKDOWN) == "3"
+ assert content.rendered_for_prompt(text_format=TextFormat.HTML) == "3"
+ assert str(content) == "3"
+
+ def test_renders_as_its_label_when_it_has_one(self):
+ """`$severity` in a later prompt reads the level's name, not its index."""
+ content = RatingContent(level=1, label="Workaround available", position=1.2)
+ assert content.rendered_plain() == "Workaround available"
+ assert content.rendered_markdown() == "Workaround available"
+ assert content.rendered_html() == "Workaround available"
+ assert content.rendered_for_prompt() == "Workaround available"
+ assert content.rendered_for_prompt(text_format=TextFormat.MARKDOWN) == "Workaround available"
+ assert content.rendered_for_prompt(text_format=TextFormat.HTML) == "Workaround available"
+ assert str(content) == "Workaround available"
+
+ @pytest.mark.asyncio(loop_scope="class")
+ async def test_renders_as_its_label_in_a_template(self):
+ """The async path a Jinja2 template's `format` filter takes reaches the same renderers."""
+ labelled = RatingContent(level=2, label="Fully blocked")
+ unlabelled = RatingContent(level=2)
+ for text_format in (TextFormat.PLAIN, TextFormat.MARKDOWN, TextFormat.HTML):
+ assert await labelled.rendered_for_template_async(text_format=text_format) == "Fully blocked"
+ assert await unlabelled.rendered_for_template_async(text_format=text_format) == "2"
+
+ def test_renders_html_with_the_label_escaped(self):
+ assert RatingContent(level=0, label="<b>Minor</b> & cosmetic").rendered_html() == "&lt;b&gt;Minor&lt;/b&gt; &amp; cosmetic"
+
+ def test_renders_as_its_level_when_the_label_is_empty(self):
+ """An empty label names nothing, so the rating falls back to its level rather than rendering as nothing."""
+ content = RatingContent(level=2, label="")
+ assert content.rendered_plain() == "2"
+ assert content.rendered_markdown() == "2"
+ assert content.rendered_html() == "2"
def test_rendered_json_writes_the_present_members_only(self):
assert json.loads(RatingContent(level=0).rendered_json()) == {"level": 0}
assert json.loads(RatingContent(level=2, position=1.8).rendered_json()) == {"level": 2, "position": 1.8}
+ assert json.loads(RatingContent(level=1, label="Workaround available").rendered_json()) == {"level": 1, "label": "Workaround available"}
+ assert json.loads(RatingContent(level=1, label="Workaround available", confidence=0.6).rendered_for_prompt(text_format=TextFormat.JSON)) == {
+ "level": 1,
+ "label": "Workaround available",
+ "confidence": 0.6,
+ }
+
+ def test_rendered_json_keeps_the_pinned_member_order(self):
+ """The label follows the level, as the standard's pinned definition orders them."""
+ rendered = RatingContent(level=1, label="Workaround available", confidence=0.6).rendered_json()
+ assert list(json.loads(rendered)) == ["level", "label", "confidence"]
def test_smart_dump_writes_absent_members_null(self):
- assert RatingContent(level=1).smart_dump() == {"level": 1, "confidence": None, "probabilities": None, "position": None}
+ assert RatingContent(level=1).smart_dump() == {"level": 1, "label": None, "confidence": None, "probabilities": None, "position": None}
+
+ def test_smart_dump_writes_the_label(self):
+ assert RatingContent(level=1, label="Workaround available").smart_dump() == {
+ "level": 1,
+ "label": "Workaround available",
+ "confidence": None,
+ "probabilities": None,
+ "position": None,
+ }
def test_short_desc_names_the_level(self):
assert RatingContent(level=2).short_desc == "a rating (level 2)"
diff --git a/uv.lock b/uv.lock
index 5ea9a671d..4bd0a735e 100644
--- a/uv.lock
+++ b/uv.lock
@@ -2738,7 +2738,7 @@ wheels = [
[[package]]
name = "mthds"
-version = "0.20.0"
+version = "0.21.0"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "httpx" },
@@ -2747,9 +2747,9 @@ dependencies = [
{ name = "tomlkit" },
{ name = "typing-extensions" },
]
-sdist = { url = "https://files.pythonhosted.org/packages/df/31/179dfe444a09ed83c6ab441f7b4f64a12a4559409337160b87da9493a378/mthds-0.20.0.tar.gz", hash = "sha256:85684266c2a17129c0b6098af6853d882e2183541c35cf556eaef37775a5bdf7", size = 281680, upload-time = "2026-10-09T16:46:49.554Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/58/99/ebe133c36b3db8cf7bb4abf60c3330f980fbd378822bcc62cddc09a989c9/mthds-0.21.0.tar.gz", hash = "sha256:c52f13b58471b07583e29d15aece925c03d3509a0ea1204b13e549d20a0b1e33", size = 282110, upload-time = "2026-10-10T12:10:30.802Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/86/33/c3a05657f3f4b40a2f7eeb86b2ec0bacd3ced55f5b4fa2a0e4b6e8468381/mthds-0.20.0-py3-none-any.whl", hash = "sha256:6fa0fa2f0e7e098afd18e6a96a6b10b2a005f22239fd471dadb880004ad94dca", size = 111489, upload-time = "2026-10-09T16:46:47.94Z" },
+ { url = "https://files.pythonhosted.org/packages/e4/1d/97001f8f2d42e904f2ce2f8a005cddb596efcdf103b413a0d22bbcd5bf67/mthds-0.21.0-py3-none-any.whl", hash = "sha256:c2ac9762980936e63864941c2107fa589c17ea367ca00dbb6a17bf4022c6beaa", size = 111488, upload-time = "2026-10-10T12:10:29.298Z" },
]
[[package]]
@@ -3708,7 +3708,7 @@ requires-dist = [
{ name = "mkdocs-meta-manager", marker = "extra == 'docs'", specifier = ">=1.1.0" },
{ name = "mkdocs-redirects", marker = "extra == 'docs'", specifier = "==1.2.2" },
{ name = "moto", extras = ["dynamodb", "s3"], marker = "extra == 'dev'", specifier = ">=5.0.0" },
- { name = "mthds", specifier = "==0.20.0" },
+ { name = "mthds", specifier = "==0.21.0" },
{ name = "mypy", marker = "extra == 'dev'", specifier = "==1.19.1" },
{ name = "networkx", specifier = ">=3.4.2" },
{ name = "openai", specifier = ">=2.0.0" },
@@ -3717,7 +3717,7 @@ requires-dist = [
{ name = "opentelemetry-sdk", specifier = ">=1.39.0" },
{ name = "opentelemetry-semantic-conventions", specifier = ">=0.59b0" },
{ name = "pillow", specifier = ">=12.1.1" },
- { name = "pipelex-sdk", specifier = "==0.37.0" },
+ { name = "pipelex-sdk", specifier = "==0.38.0" },
{ name = "pipelex-tools", marker = "extra == 'dev'", specifier = ">=0.7.2" },
{ name = "pipelex-tools-py", specifier = ">=0.1.3" },
{ name = "polyfactory", specifier = ">=2.21.0" },
@@ -3829,7 +3829,7 @@ provides-extras = ["dev"]
[[package]]
name = "pipelex-sdk"
-version = "0.37.0"
+version = "0.38.0"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "httpx" },
@@ -3837,9 +3837,9 @@ dependencies = [
{ name = "pydantic" },
{ name = "typing-extensions" },
]
-sdist = { url = "https://files.pythonhosted.org/packages/ed/82/1795a4fc8828b68eff9bedbe8ebc490ee264f5b1363f24fd5b85d6ce2f94/pipelex_sdk-0.37.0.tar.gz", hash = "sha256:92415c4c9cb1aa3280be1f4fed0afe2ed631353452ec7d44fbd4109bdfe1fe5e", size = 533442, upload-time = "2026-10-09T17:53:39.353Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/42/96/ec90e611b2fb8944e95f8fcf917093d7a1b3c9dcf60994b8c7553d0ae394/pipelex_sdk-0.38.0.tar.gz", hash = "sha256:6a2e5000408c6dbcdf06cc662df8f13accbebb1a3293616ddd90dcceefef0377", size = 533494, upload-time = "2026-10-10T13:41:06.803Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/4b/c6/6a919f8a05719e07119638f4b3762429356b0ac1d1ecfb1a8ef9966b990d/pipelex_sdk-0.37.0-py3-none-any.whl", hash = "sha256:164d2e5633366b84b18ddd4e053b490e7d595d67ebf17f32c7a7f5367acbb8b8", size = 213971, upload-time = "2026-10-09T17:53:37.271Z" },
+ { url = "https://files.pythonhosted.org/packages/71/14/01a43fc54d87e883e92ca317e0a1b8d23dfe3ef0251dbcbf9a29e101b72c/pipelex_sdk-0.38.0-py3-none-any.whl", hash = "sha256:291296c4ea5e03cd3328626c6ee68acf669f7c60d60f41ca26d489297e2820df", size = 213968, upload-time = "2026-10-10T13:41:04.946Z" },
]
[[package]]