Skip to main content

AI Message Mappers

A Message Mapper reshapes the JSON payload flowing through one operation of a published API — in one direction only. It exists to bridge the gap between how you want an agent to send/receive data and how the upstream API actually expects it, without asking the upstream to change.

  • direction: "request" — reshapes what the caller (agent) sends into what the upstream API actually expects.
  • direction: "response" — reshapes what the upstream API returns into what the caller expects.

Each mapper applies to exactly one OpenAPI operationId, in exactly one direction — you can't have two request mappers (or two response mappers) for the same operation; edit the existing one instead.


Design-Time AI, Runtime Determinism​

This is the important safety property: the AI is only ever used at save time, to propose a transform_spec from a sample pair you provide. Once saved, every real request runs that expression through a deterministic, sandboxed evaluator (the same safe_eval engine Agent Builder's own transform node uses) — never a live LLM call on the request hot path.

transform_spec is a single Python-expression string. It can use three names: input (the JSON body being reshaped), query (the incoming query parameters) and path_params (the path parameters, e.g. item_id in /items/{item_id}):

{"petName": input["name"], "petAge": input["age"], "owner": path_params["owner_id"]}

Query mapping (request mappers)​

A request mapper can also have a query mapping (query_transform_spec): an expression that returns the query parameters to send upstream, replacing the incoming ones. It uses the same names. Leave it empty to forward the query string unchanged.

{"page": query.get("p", 1), "page_size": 50, "api_version": "2"}

The result must be an object whose values are strings, numbers, booleans or lists of those; None values are dropped. A query mapping is only allowed on request mappers.

The evaluator permits:

  • Dict and list literals
  • Indexing/subscripting (input["key"], input["list"][0])
  • Arithmetic, comparison, and boolean operators, and ternary expressions
  • List, dict and set comprehensions ([x["id"] for x in input["items"]])
  • Methods on values (input["name"].upper(), query.get("p", 1))
  • A fixed whitelist of built-ins: abs, len, max, min, round, sum, any, all, zip, enumerate, map, filter, sorted, reversed, list, dict, set, tuple, bool, int, str, float, rand, randint

It does not permit lambdas, :=, imports, attributes that start with _ (such as __class__), function or class definitions, or any name other than input, query, path_params, the built-ins above and a comprehension's own variables. Saving a transform_spec or query_transform_spec that uses one of these is refused with 422 (… can never run: …), like a syntax error, so it never reaches a live call.


Endpoints​

All under /api/v1/api-definitions/{api_definition_id}:

EndpointDescription
GET /mappersList all message mappers for this API
POST /mappersCreate a mapper — operation_id, direction, optional source_sample/target_sample/transform_spec, enabled, test_cases
GET /mappers/{mapper_id}Get one mapper
PUT /mappers/{mapper_id}Update a mapper (partial — only provided fields change)
DELETE /mappers/{mapper_id}Delete a mapper
POST /mappers/generateAI-assisted: propose a transform_spec from a source_sample/target_sample pair. Doesn't save anything — review and save the proposal like any other field. 422 if the operation isn't in the API's spec.
POST /mappers/{mapper_id}/testRun the mapper's transform_spec against its saved test_cases and record pass/fail

Creating, editing, or deleting a mapper requires the api_developer, lifecycle_manager, space_admin, or admin role on the parent API (see Catalogs, Spaces & Roles).

Generating a mapper​

json
POST /mappers/generate
{
  "operation_id": "createPet",
  "direction": "request",
  "source_sample": { "name": "Rex", "age": 3 },
  "target_sample": { "petName": "Rex", "petAge": 3 }
}
json
{ "transform_spec": "{\"petName\": input[\"name\"], \"petAge\": input[\"age\"]}", "warning": null }

If the LLM call itself fails (no default model configured, provider error), you get a 502 telling you to configure a default model or write the expression by hand — mapper generation isn't scoped to any API Space's own LLM config (API Spaces intentionally carry none), it always uses the instance-wide default model.

The proposal is also dry-run against your source_sample before being returned, so an obviously broken expression is flagged immediately rather than at test time.

Testing a mapper​

json
POST /mappers/{mapper_id}/test
json
{
  "all_passed": true,
  "results": [
    { "index": 0, "passed": true, "actual_output": {"petName": "Rex", "petAge": 3}, "expected_output": {"petName": "Rex", "petAge": 3} }
  ]
}

Each entry in test_cases is {"input": ..., "expected_output": ...}, optionally with "query" and "path_params" objects when the expression uses them. The mapper needs both a saved transform_spec and at least one test case, or the endpoint returns a 400. The pass/fail result is cached on the mapper (last_test_passed, last_tested_at) so the builder UI can show status without re-running the test on every page load.


Where Mappers Run​

Every call through the API Gateway runs, for the matched operation:

Request:   validate (spec = agent shape) → message mapper → protocol mapper → upstream
Response: protocol mapper → message mapper → validate (spec = agent shape) → masking → agent

The OpenAPI spec always describes what agents send and receive; the mappers bridge to what the upstream really speaks. A request whose body isn't JSON is rejected with 400 request_not_json on an operation that has a request mapper, instead of being forwarded unmapped. Response mappers only run on 2xx responses; upstream errors pass through unchanged.

Mappers Are Part of Each Version​

Mappers are saved with every version snapshot, together with the spec:

  • APIs with environments: each environment runs the mappers of the version it serves. Editing a mapper changes the working copy (and what the test console runs against it); it reaches dev, staging and prod only when a new version is approved and promoted — exactly like a spec change.
  • APIs without environments: the working copy is what prod serves, so a mapper change on a published API takes effect on the next call. That is why changing a mapper on a published API needs a lifecycle_manager, space_admin or admin; an api_developer pulls the API back to draft first.
  • Rollback brings the mappers back to that version's: mappers the version also had are restored to its settings, and mappers it didn't have are disabled, never deleted (re-enable them if you need them). Snapshots taken before mappers were versioned leave the mappers unchanged.

transform_spec is checked when you save, so a typo, or a construct the evaluator would refuse (a lambda, an unknown name, a _ attribute), is rejected with a 422 instead of failing every live call through that operation. If a mapper still fails at call time (for example, a field missing from a real response), the gateway returns 502 request_mapping_failed or response_mapping_failed; the full error is in the server log under the response's reference.


  • AI Protocol Mappers — the other half of the pipeline, for wire-format conversion (XML/SOAP/form) rather than JSON reshaping
  • API Gateway — the exact order mappers run in on a real request
  • Tool Server Publishing — what is registered for agents; the URL is always the gateway, with or without mappers
Hrida.ai is proprietary software of Zlabs Innovation. See the license for terms. © 2026 Zlabs Innovation.