Input/Output Mapping
Map your function’s parameters and return values to Rhesis’s standardized request/response format. The SDK supports both automatic detection and manual configuration.
Auto-Mapping (Recommended)
Use standard field names for automatic detection:
Standard fields:
| Direction | Field | Description |
|---|---|---|
| Request | input | The user query or test prompt |
| Request | conversation_id | Conversation tracking identifier |
| Request | context | Additional context provided with the request |
| Request | metadata | Structured metadata passed to the endpoint |
| Request | tool_calls | Tool call data passed to the endpoint |
| Request | files | File attachments passed as FileReference objects |
| Request | params | Resolved experiment parameters available in request mappings |
| Response | output | The main response text |
| Response | context | Retrieval context (e.g., RAG sources) |
| Response | metadata | Structured response metadata (e.g., confidence scores) |
| Response | tool_calls | Tool/function calls made during response generation |
| Response | conversation_id | Conversation identifier for multi-turn tracking |
session_id remains supported as a legacy alias for existing endpoints and
mappings.
Manual Mapping
For custom parameter names or complex structures, provide explicit mappings:
Request Mapping (Jinja2 Templates)
Request mapping transforms incoming Rhesis request fields to your function parameters using Jinja2 template syntax ({{ variable_name }}). Standard fields (see the table above) and any custom fields in the request are available as template variables.
Simple Mappings
Complex Structures
For functions that accept complex types (like Pydantic models), mapping keys should match function parameter names:
See Advanced Mapping for how complex types like Pydantic models are automatically constructed from mapped dictionaries.
Experiment parameters
When a test run is associated with an experiment, resolved values are available under params. Prefer mapping those values into your function arguments instead of using the deprecated parameters= decorator option.
The legacy @endpoint(parameters=["model", "temperature"]) path still works
for older applications, but it emits a deprecation warning. Use
{{ params.* }} in request_mapping for new endpoints.
File attachments
Use the files variable when your endpoint needs test attachments. Map it directly into a function argument and handle the items as FileReference objects.
See Connector Files for raw byte access and extraction details.
Response Mapping (JSONPath or Jinja2)
Response mapping extracts values from your function’s return value to Rhesis’s standardized format.
JSONPath Syntax
Use JSONPath expressions (starting with $) for direct field extraction:
Common JSONPath patterns:
| Pattern | Description |
|---|---|
$.field | Top-level field |
$.nested.field | Nested field |
$.array[0] | First array element |
$.array[-1] | Last array element |
$.array[*].field | Field from all array elements |
Jinja2 Templates with JSONPath
Use Jinja2 templates with the jsonpath() function for conditional logic or complex extraction:
Custom Request Fields
You can pass custom fields through the API that aren’t part of the standard schema:
Custom fields must be included in the API request body when invoking the endpoint.
Next steps
- Map complex objects like Pydantic models and dataclasses.
- Handle file attachments passed as
FileReferenceobjects.