protected static List<RequestResponsePair> parseRequestResponseTemplateOutput(Service service, Operation operation,
         String content) throws Exception {
      List<RequestResponsePair> results = new ArrayList<>();

      JsonNode root = YAML_MAPPER.readTree(sanitizeYamlContent(content));
      if (root.getNodeType() == JsonNodeType.ARRAY) {
         Iterator<JsonNode> examples = root.elements();
         while (examples.hasNext()) {
            JsonNode example = examples.next();

            // Deal with parsing request.
            JsonNode requestNode = example.path("request");
            Request request = new Request();
            JsonNode requestHeadersNode = requestNode.path(HEADERS_NODE);
            request.setHeaders(buildHeaders(requestHeadersNode));
            request.setContent(getRequestContent(requestHeadersNode, requestNode.path("body")));

            String url = requestNode.path("url").asText();
            if (url.contains("?")) {
               String[] kvPairs = url.substring(url.indexOf("?") + 1).split("&");
               for (String kvPair : kvPairs) {
                  String[] kv = kvPair.split("=");
                  Parameter param = new Parameter();
                  param.setName(kv[0]);
                  param.setValue(kv[1]);
                  request.addQueryParameter(param);
               }
            }

            // Deal with parsing response.
            JsonNode responseNode = example.path("response");
            Response response = new Response();
            JsonNode responseHeadersNode = responseNode.path(HEADERS_NODE);
            response.setHeaders(buildHeaders(responseHeadersNode));
            response.setContent(getResponseContent(responseHeadersNode, responseNode.path("body")));
            response.setMediaType(responseHeadersNode.path("content-type").asText(null));
            response.setStatus(responseNode.path("code").asText("200"));
            response.setFault(response.getStatus().startsWith("4") || response.getStatus().startsWith("5"));

            //
            String dispatchCriteria = null;

            if (DispatchStyles.URI_PARTS.equals(operation.getDispatcher())) {
               String resourcePathPattern = operation.getName().split(" ")[1];
               dispatchCriteria = DispatchCriteriaHelper.extractFromURIPattern(operation.getDispatcherRules(),
                     resourcePathPattern, url);
            } else if (DispatchStyles.URI_PARAMS.equals(operation.getDispatcher())) {
               dispatchCriteria = DispatchCriteriaHelper.extractFromURIParams(operation.getDispatcherRules(), url);
            } else if (DispatchStyles.URI_ELEMENTS.equals(operation.getDispatcher())) {
               String resourcePathPattern = operation.getName().split(" ")[1];
               dispatchCriteria = DispatchCriteriaHelper.extractFromURIPattern(operation.getDispatcherRules(),
                     resourcePathPattern, url);
               dispatchCriteria += DispatchCriteriaHelper.extractFromURIParams(operation.getDispatcherRules(), url);
            } else if (DispatchStyles.QUERY_ARGS.equals(operation.getDispatcher())) {
               // This dispatcher is used for GraphQL or gRPC
               if (ServiceType.GRAPHQL.equals(service.getType())) {
                  Map<String, String> variables = getGraphQLVariables(request.getContent());
                  dispatchCriteria = DispatchCriteriaHelper.extractFromParamMap(operation.getDispatcherRules(),
                        variables);
               } else if (ServiceType.GRPC.equals(service.getType())) {
                  Map<String, String> parameters = JSON_MAPPER.readValue(request.getContent(),
                        TypeFactory.defaultInstance().constructMapType(TreeMap.class, String.class, String.class));
                  dispatchCriteria = DispatchCriteriaHelper.extractFromParamMap(operation.getDispatcherRules(),
                        parameters);
               }
            }
            response.setDispatchCriteria(dispatchCriteria);

            if (service.getType() == ServiceType.GRAPHQL) {
               adaptGraphQLRequestContent(request);
            }

            results.add(new RequestResponsePair(request, response));
         }
      }
      return results;
   }
@Test
   void testParseRequestResponseOutputSplitWithJson() {
      String aiResponse = """
            Example 1:

            - example: 1
              request:
                url: https://example.com/graphql
                headers:
                  accept: application/json
                body: |
                  {
                    "query": "query { film(id: \\"123\\") { id, title, episodeID, director, starCount, rating } }"
                  }
              response:
                code: 200
                headers:
                  content-type: application/json
                body: |
                  {
                    "data": {
                      "film": {
                        "id": "123",
                        "title": "Star Wars: Episode IV - A New Hope",
                        "episodeID": 4,
                        "director": "George Lucas",
                        "starCount": 5000,
                        "rating": 8.7
                      }
                    }
                  }

            Example 2:

            - example: 2
              request:
                url: https://example.com/graphql
                headers:
                  accept: application/json
                body: |
                  {
                    "query": "query($id: String) { film(id: $id) { id, title, episodeID, director, starCount, rating } }",
                    "variables": {
                      "id": "456"
                    }
                  }
              response:
                code: 200
                headers:
                  content-type: application/json
                body: |
                  {
                    "data": {
                      "film": {
                        "id": "456",
                        "title": "The Godfather",
                        "episodeID": 1,
                        "director": "Francis Ford Coppola",
                        "starCount": 4500,
                        "rating": 9.2
                      }
                    }
                  }
            """;

      Service service = new Service();
      service.setType(ServiceType.GRAPHQL);
      Operation operation = new Operation();
      operation.setName("film");
      operation.setDispatcher(DispatchStyles.QUERY_ARGS);
      operation.setDispatcherRules("id");
      List<RequestResponsePair> results = null;
      try {
         results = AICopilotHelper.parseRequestResponseTemplateOutput(service, operation, aiResponse);
      } catch (Exception e) {
         fail("Exception should not be thrown here");
      }

      assertNotNull(results);
      assertEquals(2, results.size());

      // Check that request 1 has been correctly parsed.
      RequestResponsePair example1 = results.get(0);
      assertNotNull(example1.getRequest().getContent());
      assertFalse(example1.getRequest().getContent().contains("\\n"));
      assertEquals(1, example1.getRequest().getHeaders().size());

      // Check that response 1 has been correctly parsed.
      assertEquals("200", example1.getResponse().getStatus());
      assertNotNull(example1.getResponse().getContent());
      assertFalse(example1.getResponse().getContent().contains("\\n"));
      assertEquals(1, example1.getResponse().getHeaders().size());

      // Check that request 2 has been correctly parsed.
      RequestResponsePair example2 = results.get(1);
      assertNotNull(example2.getRequest().getContent());
      assertFalse(example2.getRequest().getContent().contains("\\n"));
      assertEquals(1, example2.getRequest().getHeaders().size());

      // Check that response 2 has been correctly parsed.
      assertEquals("200", example1.getResponse().getStatus());
      assertNotNull(example2.getResponse().getContent());
      assertFalse(example2.getResponse().getContent().contains("\\n"));
      assertEquals(1, example2.getResponse().getHeaders().size());
      assertEquals("?id=456", example2.getResponse().getDispatchCriteria());
   }