SAP Home Learn Build Integrate Model Operate Extend with AI ConnectTutorial navigator Knowledge Graph API Devtoberfest Developer Advocates App Space

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
⤢ Open full site

Prompt Optimization with Tool Calling and Response Formatting

This tutorial demonstrates how to use Prompt Optimization in SAP AI Core for tool calling scenarios using a BFCL v3 dataset, and pairs it with SAP AI Core's **Response Formatting** feature so you can enforce structured output in two complementary ways. The process loads and normalizes a BFCL v3 parallel-multiple dataset, splits it into train and test sets, uploads all files to AI Core's built-in dataset storage, registers a dataset artifact, pushes a base prompt template to the Prompt Registry, and runs an optimization execution targeting Gemini 2.5 Pro with GPT-4o as the reference model using the `JSON_Match` metric. Alongside the optimizer, it introduces the Orchestration Service `response_format` parameter (`text`, `json_object`, `json_schema`) — an API-level way to guarantee valid JSON independent of prompt wording — and builds a JSON Schema from the unioned tool definitions. After completion, the optimized prompt is retrieved and compared against the base prompt through live inference, both with and without a `response_format` schema attached.

Overview

🎓 beginner 50 min. SAP Ai CoreBeginnerArtificial IntelligenceMachine Learning

You will learn

  • How to load and normalize BFCL v3 parallel-multiple data into the SAP optimizer golden format.
  • How Response Formatting works (text, json_object, json_schema) and how it complements prompt optimization.
  • How to build a json_schema response_format from the unioned BFCL tool definitions.
  • How to upload train, test, tools, and prompt template files to AI Core dataset storage.
  • How to register a dataset artifact linking the uploaded folder to the genai-optimizations scenario.
  • How to create and register a base prompt template in the Prompt Registry.
  • How to configure and run prompt optimization via Python SDK and Bruno.
  • How to monitor execution progress and retrieve the optimized prompt.
  • How to compare base vs optimized prompt outputs through live inference, with and without a response_format schema.
Smita Naik S Smita Naik July 29, 2026
Created by July 29, 2026
Contributors

Prerequisites

Prerequisites

  1. BTP Account
    Set up your SAP Business Technology Platform (BTP) account.
    Create a BTP Account
  2. For SAP Developers or Employees
    Internal SAP stakeholders should refer to the following documentation: How to create BTP Account For Internal SAP Employee, SAP AI Core Internal Documentation
  3. For External Developers, Customers, or Partners
    Follow this tutorial to set up your environment and entitlements: External Developer Setup Tutorial, SAP AI Core External Documentation
  4. Create BTP Instance and Service Key for SAP AI Core
    Follow the steps to create an instance and generate a service key for SAP AI Core:
    Create Service Key and Instance
  5. AI Core Setup Guide
    Step-by-step guide to set up and get started with SAP AI Core:
    AI Core Setup Tutorial
  6. An Extended SAP AI Core service plan is required, as the Generative AI Hub is not available in the Free or Standard tiers. For more details, refer to
    SAP AI Core Service Plans
  7. You have access to the genai-optimizations scenario and have the required roles such as genai_manager or custom_evaluation.
  8. A BFCL v3 dataset file (e.g., BFCL_v3_parallel_multiple_10tools.json) is available locally.
  9. A running Orchestration Service deployment in your resource group. Response Formatting and the live inference comparison are executed through the Orchestration /completion endpoint, so you need its deployment URL. See Create a Deployment for Orchestration.

Steps

Step 1 Pre-Read

Before starting this tutorial, ensure that you:

  • Understand the basics of Generative AI workflows in SAP AI Core.
  • Are familiar with function calling / tool calling concepts in LLMs.
  • Are familiar with creating and managing prompt templates and artifacts in SAP AI Core.
  • Understand, at a high level, that there are two complementary ways to push a model toward structured output:
    • Prompt optimization — automate the trial-and-error of prompt engineering so the model’s reasoning reliably produces the right structure.
    • Response Formatting — an Orchestration Service parameter that constrains the model’s output at the API level, independent of prompt wording.
  • Have completed the Quick Start tutorial or equivalent setup for SAP AI Core access.
Step 2 Architecture Overview
+
Step 3 Notebook Reference
+
Step 4 Environment Variables Setup
+
Step 5 Configure Optimization Parameters
+
Step 6 Load and Normalize the BFCL v3 Dataset
+
Step 7 Upload Files and Register Dataset Artifact
+
Step 8 Create and Register the Base Prompt Template
+
Step 9 Register an Optimization Configuration
+
Step 10 Run the Prompt Optimization Execution
+
Step 11 Monitor Optimization Progress
+
Step 12 Review Optimization Results
+
Step 13 Compare Base vs Optimized Prompt via Live Inference (with Response Formatting)
+
Step 14 Summary
+

Resources

Discussion

Share feedback on this tutorial or join the conversation in SAP Community.

Submit detailed feedback Discuss in Community
Steps
Step 1 of 14
1. Pre-Read 2. Architecture Overview 3. Notebook Reference 4. Environment Variables Setup 5. Configure Optimization Parameters 6. Load and Normalize the BFCL v3 Dataset 7. Upload Files and Register Dataset Artifact 8. Create and Register the Base Prompt Template 9. Register an Optimization Configuration 10. Run the Prompt Optimization Execution 11. Monitor Optimization Progress 12. Review Optimization Results 13. Compare Base vs Optimized Prompt via Live Inference (with Response Formatting) 14. Summary

Learn more →