https://promptfoo.dev/ logo
I am trying to make use of transform for JSON outp...
# ❓|questions
k
My test.yaml looks like this:
Copy code
- vars:
    language: English
    weightInitial: 100
    weightGoal: 80
    goals: weight loss/get more active
    diagnosisDescription: Diabetes type 2 / Essential hypertension
    country: United Kingdom
    currentMonth: March
    timelineWindowPast2DaysPatientEntries: weight, activity
  options:
    transform: |
        var json_output = JSON.parse(output);
        var feedbacks = json_output.map(function(item) {
          return item.feedback;
        });
        return feedbacks;
  assert:
    - type: llm-rubric
      value: The message must be written in British English vocabulary not American English
I am using Gemini model and my prompt is expected to give a JSON output with key "feedbacks" which is an array of JSON objects each with key feedback in it. Can someone please help. I am using the latest version of promptfoo 0.48.0
i
What's the error that you're getting?
k
TypeError: json_output.map is not a function
i
it means the parsed json is not an array. do you know what exactly is in
output
?
k
Found it. The output JSON returned an unexpected response. The code now runs. Another question: I see after parsing the web view show the transformed output. Is it possible to show the actual output? The use-case is, that the LLM responds with an array of feedbacks with
feedback
and a few other keys. I want to run the assertions on all the
feedback
values. At the end when I show a response in webview I still want the same output returned by the LLM