Repository navigation
Export replace_text_blocks, canonical_value and the JSON schema validator - #64
Conversation
Tool definitions are now checked for structural problems such as missing names, duplicate parameters, and malformed schemas, so invalid tools fail early with a clear error instead of surfacing later during inference. Validation results are cached alongside the parsed definitions. Auto-committed-on: dragonfly Co-authored-by: Medulla <medulla@tinyhumans.ai>
Extend the replace_text_blocks test to assert that JSON blocks surrounding text are preserved in place, and add cases for empty content and empty replacement text. The remaining changes are rustfmt reflowing existing assertions. Auto-committed-on: dragonfly Co-authored-by: Medulla <medulla@tinyhumans.ai>
Tiny Sweeper reviewTiny Sweeper completed its review; deterministic results follow. State: Ready for maintainer review Review snapshot
Completeness: Complete What changedIn `crates/tinyinference-llm/src/cache/mod.rs`, `canonical_value` is made public with rustdoc explaining that host crates should canonicalize cache keys the same way so equal requests do not hash apart (`#[must_use]` added). In `crates/tinyinference-llm/src/prompt_tools/mod.rs`, `replace_text_blocks` is made public with rustdoc explaining hosts with their own tool-call recovery can rewrite visible text identically. In `crates/tinyinference-llm/src/tool.rs`, `validate_schema_value` is renamed to the public `validate__value` with rustdoc describing the structural JSON Schema subset supported (type including unions, properties, required, additionalProperties: false, items, enum; unknown keywords ignored; empty/null schema imposes nothing) and its `Error::Validation` behavior; `ToolSchema::validate_call` now calls the renamed function. Two error messages for missing `type` were improved to include the actual value kind via `_value_kind`. In `crates/tinyinference-llm/tests/tool_validation.rs`, new integration tests cover the validator's error paths and permissive-schema behavior, canonical key sorting at every depth, and text-block replacement semantics. Features
Tests
FindingsNo active actionable findings. Before mergeNone. How this fits togetherflowchart LR
n0["recover_tool_calls<br/>changed"]:::changed
n1["ToolDelta<br/>changed"]:::changed
n2["ToolSchema<br/>changed"]:::changed
n3["...rguments_fail_even_with_permissive_schema<br/>changed"]:::changed
n4["schema"]:::impacted
n5["scrub_prompt_guided_item"]:::impacted
n6["MessageDelta"]:::impacted
n7["stream"]:::impacted
n8["invalid"]:::impacted
n3 -->|calls| n8
n3 -->|tests| n8
n4 -->|uses| n2
n5 -->|calls| n0
n5 -->|uses| n2
n5 -->|calls| n6
n5 -->|uses| n6
n6 -->|uses| n1
n7 -->|calls| n0
n7 -->|calls| n5
n7 -->|uses| n6
classDef changed fill:#0d4429,stroke:#238636,color:#e6edf3
classDef impacted fill:#161b22,stroke:#6e7681,color:#c9d1d9
classDef flagged fill:#5a1e02,stroke:#d93f0b,color:#ffffff
classDef blocking fill:#67060c,stroke:#f85149,color:#ffffff
Agent review detailscritique
security
tests
commits
description
e2e
Evidence and run details
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (4)
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe change makes JSON canonicalization, text-block replacement, and JSON schema validation functions public. It also renames the validator, updates its recursive calls, adds JSON value kinds to some validation errors, and adds tests for these behaviors. ChangesJSON canonicalization
Text block replacement
JSON schema validation
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Feature Merge Risk: ⚪ Minimal · up to This change exposes three existing helpers for reuse and slightly improves one validation error message. No actionable merge risk remains. Security Architecture ReviewSecurity architecture risk: ⚪ Minimal · up to The new APIs expose existing data-processing behavior without adding tool-execution authority or weakening the existing tool-call checks. No material security risk was found in the reviewed change. Downstream integrations remain responsible for authorization and correct use of the structural validator. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
A rabbit checks the keys in a row Comment |
There was a problem hiding this comment.
tinysweeper found nothing blocking. Approving.
$0.0029 · 70,112 in / 3,884 out · 8,272 cached (12%) · gpt-5.6-luna, glm-5.3-flash
critique: $0.0015 · 27,487 in / 1,644 out · 4,284 cached (16%) · gpt-5.6-luna
security: $0.0012 · 25,644 in / 638 out · 3,796 cached (15%) · gpt-5.6-luna
tests: $0.0001 · 6,153 in / 199 out · 64 cached (1%) · glm-5.3-flash
description: $0.0000 · 5,886 in / 54 out · 64 cached (1%) · glm-5.3-flash
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7d0396f41a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| /// | ||
| /// Returns [`crate::Error::Validation`] naming the first failing instance | ||
| /// path. | ||
| pub fn validate_json_value(schema: &Value, value: &Value, path: &str) -> crate::Result<()> { |
There was a problem hiding this comment.
Expose shared helpers from a supported public crate
This public export, together with the new cache::canonical_value and prompt_tools::replace_text_blocks exports, is explicitly intended for consumption by TinyAgents, but repository policy designates only tinyinference-core and tinyinference-local as public crates and assigns provider-neutral inference, cache, message, and tool-call APIs to core. Depending on these helpers through tinyinference-llm creates a new unsupported cross-repository API boundary; place the normalized helpers/types behind the core public surface instead (or update the repository architecture policy as part of the change).
AGENTS.md reference: AGENTS.md:L12-L18
Useful? React with 👍 / 👎.
Summary
Makes three
tinyinference-llmhelpers public so tinyagents can stop carrying private copies of them. tinyanalyzer's clone detection found the tinyagents harness duplicating each one; its copies have identical bodies apart from visibility and comments.prompt_tools::replace_text_blocks: rewrites a response's visible text after tool-call recovery while keeping non-text blocks (reasoning) in place.cache::canonical_value: sorts JSON object keys recursively so cache keys are canonical. Sharing it also means the two crates can't drift apart and hash equal requests differently.tool::validate_json_value(formerly the privatevalidate_schema_value): the structural JSON-Schema subset tool arguments are held to.Behavior change
One error message changes. When a schema has
requiredorpropertiesbut notype, and the value is not an object, the message was… must be an object with declared fields. It is now… must be an object with the declared fields, got <kind>, which matches the tinyagents wording and names the actual kind. Nothing in this repo asserts the old text.Everything else is additive: three new public functions, no signature changes.
Validation
cargo fmt --all -- --checkpassescargo clippy --all-targets --all-features -- -D warningspassescargo test --all-featurespassesTests
tests/tool_validation.rscovers the three public functions through the public API:Related
The tinyagents PR that deletes its copies depends on this one and will follow.
Summary by CodeRabbit