Skip to content

fix(agent): send the json value returned by to_model_output instead of the raw tool result - #37

Merged
alexb-openrouter merged 3 commits into
mainfrom
devin/1795092818-honor-json-to-model-output
Nov 23, 2026
Merged

alexb-openrouter merged 3 commits into
mainfrom
devin/1795092818-honor-json-to-model-output

Conversation

@alexb-openrouter

@alexb-openrouter alexb-openrouter commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Risk: a tool whose to_model_output returns {"type": "json", "value": ...} (for example, to drop private fields before the model sees them) had that value ignored. The SDK sent the full raw tool result to the model instead, so anything the converter meant to hide reached model context.

ToModelOutputResult.type is declared as Literal["content", "json"], but ModelResult._tool_result_to_output only honored "content"; every other result fell through to json_dumps(result["result"]).

 if isinstance(converted, Mapping) and converted.get("type") == "content":
     output = converted.get("value", [])
+elif isinstance(converted, Mapping) and converted.get("type") == "json":
+    output = json_dumps(converted.get("value"))
 else:
     output = json_dumps(result.get("result"))

tests/unit/test_to_model_output_json.py runs a tool that returns a private field, redacts it with sync and async json converters, and asserts the follow-up function_call_output holds only the converter's value. Both json tests fail on main (the private value appears in the output) and pass with the fix; the content path is covered to guard against regressions.

Local: ruff check ., ruff format --check ., mypy src tests, pytest tests/unit (145 passed).

Note for the upstream port: the TypeScript toModelOutput type only allows content, so a sync should keep this json branch.

@devin-ai-integration

devin-ai-integration Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access that start with 'Devin'.

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration
devin-ai-integration Bot marked this pull request as ready for review November 19, 2026 12:54
@OpenRouterTeam OpenRouterTeam deleted a comment from devin-ai-integration Bot Nov 23, 2026
@alexb-openrouter
alexb-openrouter merged commit d52c22c into main Nov 23, 2026
7 checks passed
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