FEAT: Runtime capability discovery for prompt targets#1699
FEAT: Runtime capability discovery for prompt targets#1699hannahwestra25 wants to merge 27 commits into
Conversation
…lities in verify_target_async
…ra/query_target_capabilities
…ra/query_target_capabilities
…ra/query_target_capabilities
| _user_text_piece(value="part one", conversation_id=conversation_id), | ||
| _user_text_piece(value="part two", conversation_id=conversation_id), |
There was a problem hiding this comment.
but it could accept multiple pieces of different types, right? Like image + text
jsong468
left a comment
There was a problem hiding this comment.
Great work! see Roman's question about how this feature gets used
| return queried | ||
|
|
||
|
|
||
| async def discover_target_async( |
There was a problem hiding this comment.
This is a little confusing in terms of how they are grouped. Isn't modality a type of capability? For example, we have TargetCapabilities.input_modalities.
Should we just have one function, discover_target_capabilities_async? But potentially include modality capabilities. E.g. input_text could be a capability name.
There was a problem hiding this comment.
Actually, I understand the reason why modalities is separate. It makes sense because it may be tough to flatten.
However, I think there should just be one public method. discover_target_capabilities_async. It can be this method, and I think most people will just call it with the target.
Description
Adds query_target_capabilities.py, which probes a
PromptTargetat runtime to determine what the underlying endpoint actually accepts. Useful for custom OpenAI-compatible endpoints, gateways that strip features, or any deployment where declared capabilities may not match real behavior.New public API (exported from
pyrit.prompt_target)discover_target_capabilities_async— probes boolean capability flags (SYSTEM_PROMPT,MULTI_MESSAGE_PIECES,MULTI_TURN,JSON_OUTPUT,JSON_SCHEMA).discover_target_modalities_async— probes which input-modality combinations are accepted.discover_target_async— runs both and returns a populatedTargetCapabilities.Each probe is bounded by
per_probe_timeout_s(default 30s) and retried once on transient errors. The target's configuration is temporarily replaced with a permissive one so_validate_requestdoesn't short-circuit. Probe-written memory rows are tagged withprompt_metadata["capability_probe"] == "1".Caveats (in docstrings)
Tests & docs
Also fix a test_common_net_utility.py which was mocking get_httpx_client with a bare MagicMock, which did not match the real async context-manager flow used by make_request_and_raise_if_error_async. That let the mocked response behave like raise_for_status was async, so production’s correct synchronous call triggered the coroutine was never awaited warning. The fix was to mock the async context manager explicitly, keep client.request as an AsyncMock, and return a real httpx.Response so raise_for_status stays synchronous like the real API.