Repository navigation
feat(validation): add tool definition and message content validators - #1
Merged
Merged
Conversation
Port identark/validation.py to src/validation.ts: - validateToolDefinitions: OpenAI function-calling schema checks, throws ConfigurationError on malformed tools - validateToolResultJson: warns (console.warn) on non-JSON tool results - validateMessageContent: string | content-block array | null Wire validateToolDefinitions into DirectGateway invokeLlm/invokeLlmStream (as Python's DirectGateway does) and export all three from the package index. MockGateway is left unvalidated, matching the Python MockGateway. ControlPlaneGateway wiring is deferred to PR identArk#8. Co-Authored-By: Claude <noreply@anthropic.com>
Goldokpa
pushed a commit
that referenced
this pull request
Oct 9, 2026
) Port identark/validation.py to src/validation.ts: - validateToolDefinitions: OpenAI function-calling schema checks, throws ConfigurationError on malformed tools - validateToolResultJson: warns (console.warn) on non-JSON tool results - validateMessageContent: string | content-block array | null Wire validateToolDefinitions into DirectGateway invokeLlm/invokeLlmStream (as Python's DirectGateway does) and export all three from the package index. MockGateway is left unvalidated, matching the Python MockGateway. ControlPlaneGateway wiring is deferred to PR #8. Co-authored-by: Kem-Ada <283358351+Kem-Ada@users.noreply.github.com>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ports the Python SDK's
identark/validation.pyto TypeScript assrc/validation.ts, bringing the three validators into the TS SDK:validateToolDefinitions(tools)checks that tools follow the OpenAI function-calling schema and throwsConfigurationErroron malformed input.validateToolResultJson(content, toolName)callsconsole.warn(never throws) when a tool result isn't valid JSON.validateMessageContent(content)accepts a string, an array of content blocks (each needs atype), ornull/undefined. It throwsConfigurationErrorotherwise.validateToolDefinitionsnow runs at the start ofDirectGateway.invokeLlm/invokeLlmStream, so malformed tools are rejected before any provider call. As in Python,MockGatewaydoes not validate. All three functions are exported from the package index.Wiring into
ControlPlaneGatewayis deferred to PR #8 (control plane).Python → TS parity mapping
identark/validation.py)src/validation.ts)validate_tool_definitions(tools)validateToolDefinitions(tools)None→undefined/null.validate_tool_result_json(content, tool_name)validateToolResultJson(content, toolName)logger.warning→console.warn(the TS SDK has no logger).validate_message_content(content)validateMessageContent(content)str | list[dict] | None→string | object[] | null | undefined.logger.debug(... parameters missing 'type' ...)ConfigurationErrorConfigurationErrorDirectGateway.invoke_llm/invoke_llm_streamcallvalidate_tool_definitionsDirectGateway.invokeLlm/invokeLlmStreaminvokeLlmvalidates after the cost-cap check, and the stream validates before it (as in Python).MockGatewaydoes not validateMockGatewaydoes not validateControlPlaneGateway.invoke_llm*callvalidate_tool_definitionsError wording uses TS terms: "must be an array" / "must be an object" instead of Python's "must be a list" / "must be a dict", and type names are
array/object/numberinstead oflist/dict/int. Everything else in the messages matches Python word for word (e.g.tools[0] missing required 'type' field,tools[1].function.name must be a non-empty string).Test plan
New file
tests/validation.test.ts(30 tests) mirrors every case intests/unit/test_validation.py(22 cases) and adds:function.name, arrayparameters, plain-object message content, index reporting (tools[1])parameterswithouttype,nullfor tools and contentDirectGatewayinvoke and stream reject bad tools without calling the provider or growing history; valid tools reach the provider unchanged;MockGatewaystill accepts unvalidated tools (parity with Python)Gate output (run locally on this branch):
Baseline before this PR: 54 tests / 6 files. After: 84 tests / 7 files (+30).
Control-plane: untouched (check_scope OK)
🤖 Generated with Claude Code