Skip to content

Commit 97f02ab

Browse files
google-genai-botcopybara-github
authored andcommitted
fix: Check input validity before appending to example
PiperOrigin-RevId: 800844445
1 parent 855da19 commit 97f02ab

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

core/src/main/java/com/google/adk/examples/ExampleUtils.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,15 @@ private static String convertExamplesToText(List<Example> examples) {
6262
for (int exampleNum = 0; exampleNum < examples.size(); exampleNum++) {
6363
Example example = examples.get(exampleNum);
6464
StringBuilder output = new StringBuilder();
65-
output
66-
.append(String.format(EXAMPLE_START, exampleNum + 1))
67-
.append(USER_PREFIX)
68-
.append(example.input().parts().get().get(0).text().get())
69-
.append("\n\n");
65+
if (example.input().parts().isPresent()
66+
&& !example.input().parts().get().isEmpty()
67+
&& example.input().parts().get().get(0).text().isPresent()) {
68+
output
69+
.append(String.format(EXAMPLE_START, exampleNum + 1))
70+
.append(USER_PREFIX)
71+
.append(example.input().parts().get().get(0).text().get())
72+
.append("\n\n");
73+
}
7074

7175
for (Content content : example.output()) {
7276
String rolePrefix = content.role().orElse("").equals("model") ? MODEL_PREFIX : USER_PREFIX;

0 commit comments

Comments
 (0)