Skip to content

[OPIK-5326] [SDK] feat: cast job input values to declared param types in runner#5952

Merged
petrotiurin merged 11 commits intomainfrom
petrotiurin/OPIK-5326-cast-job-input-values-to-declared-param-types
Apr 1, 2026
Merged

[OPIK-5326] [SDK] feat: cast job input values to declared param types in runner#5952
petrotiurin merged 11 commits intomainfrom
petrotiurin/OPIK-5326-cast-job-input-values-to-declared-param-types

Conversation

@petrotiurin
Copy link
Copy Markdown
Contributor

Details

Add input type casting to both the TypeScript and Python in-process runner loops. Previously, job inputs were passed directly to agent functions with no conversion — causing incorrect behaviour when the server serialises primitive values as strings (e.g. "42", "true").

Each SDK now maps inputs through a castInputValue / cast_input_value helper that uses the declared Param.type to coerce values to their correct native type before calling the agent function. Complex types (dict/list/object/array) are JSON-serialised as strings, matching the existing pattern in typeHelpers.ts.

Change checklist

  • User facing
  • Documentation update

Issues

  • OPIK-5326

AI-WATERMARK

AI-WATERMARK: yes

  • Tools: Claude Code
  • Model(s): claude-sonnet-4-6
  • Scope: full implementation
  • Human verification: code review + tests reviewed

Testing

TypeScript SDK

cd sdks/typescript && npx vitest run tests/unit/runner/
  • 83 tests, all passing (34 new in castInputValue.test.ts)

Python SDK

cd sdks/python && python -m pytest tests/unit/runner/test_cast_input_value.py -v
  • 46 tests, all passing

Both test suites use parametrisation to cover:

  • Each type individually (null passthrough, string coercion, native passthrough)
  • Multi-param combination scenarios (all strings, all native, mixed, objects serialised)
  • Unknown type fallback to string behaviour
  • opik_args passthrough (Python only — key not in registered params)

Documentation

N/A — internal runner implementation detail, no public API surface changed.

@github-actions github-actions bot added dependencies Pull requests that update a dependency file python Pull requests that update Python code tests Including test files, or tests related like configuration. typescript *.ts *.tsx Python SDK TypeScript SDK labels Mar 30, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 30, 2026

TS SDK E2E Tests - Node 20

275 tests   273 ✅  16m 32s ⏱️
 32 suites    2 💤
  1 files      0 ❌

Results for commit 83fd452.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 30, 2026

Python SDK E2E Tests Results (Python 3.13)

361 tests   359 ✅  13m 34s ⏱️
  1 suites    2 💤
  1 files      0 ❌

Results for commit 83fd452.

♻️ This comment has been updated with latest results.

petrotiurin added a commit that referenced this pull request Mar 30, 2026
…ner casting

Address baz-reviewer feedback on PR #5952:

TypeScript (comment #3009010633): castInputValue now delegates to
deserializeValue() from typeHelpers.ts for string→boolean and string→number
conversions. Adds a Number.isNaN guard so non-numeric strings (e.g. "abc")
throw TypeError instead of silently passing NaN to the agent function.

Python (comment #3009010639): extract_params now calls unwrap_optional()
from type_helpers.py before extracting the type name, so Optional[int]
annotations correctly store type="int" instead of the raw
"typing.Optional[int]" string. cast_input_value is rewritten to delegate to
backend_value_to_python_value() from type_helpers.py, unifying the
conversion logic across AgentConfig and the runner.

Python (comment #3009010648): renamed all test functions in
test_cast_input_value.py to follow the repo convention
test_WHAT__CASE_DESCRIPTION__EXPECTED_RESULT. Added tests for Optional[T]
unwrapping in extract_params and for the new backend type name aliases
("boolean", "integer", "string").

Skipping comment #3009010644 (bool "1"→True): strict "true"/"false" only
behaviour is intentional and mirrors the TypeScript SDK — the backend
serialises booleans as true/false, not "1"/"yes".

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 30, 2026

Python SDK Unit Tests Results (Python 3.14)

2 440 tests   2 440 ✅  43s ⏱️
    1 suites      0 💤
    1 files        0 ❌

Results for commit f682c5e.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 30, 2026

Python SDK Unit Tests Results (Python 3.13)

2 440 tests   2 440 ✅  58s ⏱️
    1 suites      0 💤
    1 files        0 ❌

Results for commit f682c5e.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 30, 2026

Python SDK Unit Tests Results (Python 3.12)

2 440 tests   2 440 ✅  58s ⏱️
    1 suites      0 💤
    1 files        0 ❌

Results for commit f682c5e.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 30, 2026

Python SDK Unit Tests Results (Python 3.11)

2 440 tests   2 440 ✅  59s ⏱️
    1 suites      0 💤
    1 files        0 ❌

Results for commit f682c5e.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 30, 2026

Python SDK Unit Tests Results (Python 3.10)

2 445 tests   2 445 ✅  1m 2s ⏱️
    1 suites      0 💤
    1 files        0 ❌

Results for commit 08f02af.

♻️ This comment has been updated with latest results.

@github-actions github-actions bot removed the dependencies Pull requests that update a dependency file label Mar 30, 2026
petrotiurin and others added 8 commits March 30, 2026 18:24
… in runner

Add input type casting to both the TypeScript and Python in-process runner
loops so agent functions receive correctly-typed arguments regardless of how
the server serialised the values in job.inputs.

TypeScript: export castInputValue() from InProcessRunnerLoop, apply it in
invokeAgent using each Param's declared type (boolean / number / string).

Python: add cast_input_value() to in_process_loop, apply it in _execute_job
for all keys that match a registered param (bool / int / float / str); keys
such as opik_args that are not in params pass through unchanged.

Both implementations follow the same pattern as typeHelpers.ts: primitives
are cast natively, complex types (dict/list) are JSON-serialised as strings,
and null/None passes through unchanged.

Unit tests added for both SDKs using parametrisation to cover each type
individually and a set of multi-param combination scenarios.

Implements OPIK-5326

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ner casting

Address baz-reviewer feedback on PR #5952:

TypeScript (comment #3009010633): castInputValue now delegates to
deserializeValue() from typeHelpers.ts for string→boolean and string→number
conversions. Adds a Number.isNaN guard so non-numeric strings (e.g. "abc")
throw TypeError instead of silently passing NaN to the agent function.

Python (comment #3009010639): extract_params now calls unwrap_optional()
from type_helpers.py before extracting the type name, so Optional[int]
annotations correctly store type="int" instead of the raw
"typing.Optional[int]" string. cast_input_value is rewritten to delegate to
backend_value_to_python_value() from type_helpers.py, unifying the
conversion logic across AgentConfig and the runner.

Python (comment #3009010648): renamed all test functions in
test_cast_input_value.py to follow the repo convention
test_WHAT__CASE_DESCRIPTION__EXPECTED_RESULT. Added tests for Optional[T]
unwrapping in extract_params and for the new backend type name aliases
("boolean", "integer", "string").

Skipping comment #3009010644 (bool "1"→True): strict "true"/"false" only
behaviour is intentional and mirrors the TypeScript SDK — the backend
serialises booleans as true/false, not "1"/"yes".

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
type_helpers.py / typeHelpers.ts were under agent_config but are now
used by the runner as well. Move them to a neutral location:

  Python:     api_objects/agent_config/type_helpers.py
           →  api_objects/type_helpers.py

  TypeScript: agent-config/typeHelpers.ts
           →  typeHelpers.ts  (opik package root)

Update all import sites in both SDKs: agent_config internals
(config, blueprint, base, AgentConfig, Blueprint, index), the runner
(in_process_loop, registry), the client (Client.ts), and all
corresponding test files.  No logic changes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…n in_process_loop

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…type names

- Remove backend_type param from backend_value_to_python_value (was unused)
- Raise TypeError for truncating int casts ("3.9") and bool→int coercion
- registry.extract_params now emits backend type names (integer/boolean/string)
  so Param.type is consistent with what the server expects
- cast_input_value delegates directly to backend_type_to_python_type; the
  dual Python/backend name lookup (type_name_to_python_type) is removed
- Add _execute_job integration tests covering multi-typed params in both
  Python and TypeScript

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…iled jobs

- Extend bool casting to accept "1" and "yes" as truthy values
- Move input casting inside _execute_job's try/except so TypeError
  from invalid inputs is reported to the backend as a failed job
  instead of propagating uncaught

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@petrotiurin petrotiurin force-pushed the petrotiurin/OPIK-5326-cast-job-input-values-to-declared-param-types branch from 08f02af to e1a0e09 Compare March 30, 2026 17:25
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@petrotiurin petrotiurin marked this pull request as ready for review March 31, 2026 12:35
@petrotiurin petrotiurin requested a review from a team as a code owner March 31, 2026 12:35
Copy link
Copy Markdown
Contributor

@awkoy awkoy left a comment

Choose a reason for hiding this comment

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

LGTm!

@petrotiurin petrotiurin merged commit 0db0ac7 into main Apr 1, 2026
155 checks passed
@petrotiurin petrotiurin deleted the petrotiurin/OPIK-5326-cast-job-input-values-to-declared-param-types branch April 1, 2026 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Python SDK python Pull requests that update Python code tests Including test files, or tests related like configuration. TypeScript SDK typescript *.ts *.tsx

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants