Skip to content

Template model fails to parse top level JSON Array in Response #1090

Description

@Lokiiiiii

Problem

For a custom endpoint whose response is a top-level JSON array (e.g. a reranker returning [{"index":0,"score":0.98}, ...]), a response_field JMESPath that resolves to a scalar (e.g. [0].score) can't be converted (convert_to_response_data, base_endpoint.py:445, handles only list/str/None).

Depending on endpoint class, the outcome is either a silent empty parse or a crash — with no message pointing at the real cause.

template_endpoint.py:185-186 returns None when the value can't convert. But it fails silently (response parsed as zero data), with no diagnostic naming the path or the fix.

Raw endpoint (RawEndpoint(JMESPathResponseMixin,...), raw_endpoint.py:13): crashes. After a None convert it falls through (response_mixin.py:106-107) to auto_detect_and_extract(json_obj).

Any endpoint with no response_field + top-level array: also crashes (template else at template_endpoint.py:188; raw fallthrough).

Crash mechanism: auto_detect_and_extract(json_obj: dict) (base_endpoint.py:327) and helpers call json_obj.get(...) unguarded (e.g. try_extract_embeddings, line 363: json_obj.get("data")). get_json() (record_models.py:342) returns load_json_str(...), so a top-level array yields a list despite the JsonObject(=dict) annotation (types.py:47) — the list reaches .get() and raises AttributeError: 'list' object has no attribute 'get'.

Suggested fixes

Guard auto_detect_and_extract / try_extract_* with isinstance(json_obj, dict); on a top-level list, handle it (rankings/embeddings) or raise a clear message. Fixes the crash and future-proofs all callers.
When a compiled response_field yields an unconvertible value, log a clear warning naming the path + resolved type + the "@" hint — on both template and raw paths — instead of a silent None.

Repro

Endpoint returns [{"index":0,"score":0.98}]; set response_field: "[0].score"; run aiperf profile. → raw: AttributeError; template: run "succeeds" with zero parsed data.

Workaround

response_field: "@" (identity) → passes the whole array → maps to RankingsResponseData.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions