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 testParseRequestResponseOutputYamlWithMD() {
      String aiResponse = """
            ##### Example 1:

            Request:
            ```yaml
            example: 1
            request:
              url: "/pastries?size=L"
              headers:
                accept: application/json
              body:
            response:
              code: 200
              headers:
                content-type: application/json
              body:
                - name: "Croissant"
                  description: "A buttery, flaky, viennoiserie pastry named for its well-known crescent shape"
                  size: "L"
                  price: 3.49
                  status: "available"
                - name: "Pain au Chocolat"
                  description: "A sweet, buttery pastry filled with dark chocolate"
                  size: "L"
                  price: 4.99
                  status: "available"
                - name: "Danish"
                  description: "A multilayered, laminated sweet pastry in the viennoiserie tradition"
                  size: "L"
                  price: 2.99
                  status: "available"
            ```

            ##### Example 2:

            Request:
            ```yaml
            example: 2
            request:
              url: "/pastries?size=M"
              headers:
                accept: application/json
              body:
            response:
              code: 200
              headers:
                content-type: application/json
              body:
                - name: "Eclair"
                  description: "An oblong pastry made with choux dough filled with a cream and topped with icing"
                  size: "M"
                  price: 2.99
                  status: "available"
                - name: "Macaron"
                  description: "A sweet meringue-based confection made with egg white, icing sugar, granulated sugar, almond flour, and food coloring"
                  size: "M"
                  price: 1.99
                  status: "available"
                - name: "Madeleine"
                  description: "A small sponge cake traditionally baked in scallop-shaped madeleine molds"
                  size: "M"
                  price: 2.49
                  status: "available"
            ```
            """;

      Service service = new Service();
      service.setType(ServiceType.REST);
      Operation operation = new Operation();
      operation.setName("GET /pastries");
      operation.setDispatcher(DispatchStyles.URI_PARAMS);
      operation.setDispatcherRules("size");

      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);
      assertNull(example1.getRequest().getContent());
      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());
      assertEquals("?size=L", example1.getResponse().getDispatchCriteria());
   }