Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ internal class JsonSchemaValidator private constructor() {
private const val MAX_ENUM_TOTAL_STRING_LENGTH = 7_500

/** The maximum depth (number of levels) of nesting allowed in a schema. */
private const val MAX_NESTING_DEPTH = 5
private const val MAX_NESTING_DEPTH = 10

/** The depth value that corresponds to the root level of the schema. */
private const val ROOT_DEPTH = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,12 @@ internal class StructuredOutputsTest {
@Test
@Suppress("unused")
fun schemaTest_deepNestingBeyondLimit() {
class U(val s: String)
class A(val s: String)
class Q(val u: A)
class R(val u: Q)
class S(val u: R)
class T(val u: S)
class U(val u: T)
class V(val u: U)
class W(val v: V)
class X(val w: W)
Expand All @@ -893,7 +898,8 @@ internal class StructuredOutputsTest {
validator.validate(schema)

assertThat(validator.errors()).hasSize(1)
assertThat(validator.errors()[0]).contains("Current nesting depth is 6, but maximum is 5.")
assertThat(validator.errors()[0])
.contains("Current nesting depth is 11, but maximum is 10.")
}

@Test
Expand Down Expand Up @@ -1736,7 +1742,12 @@ internal class StructuredOutputsTest {
@Suppress("unused")
fun responseFormatFromClassFailureWithValidation() {
// Exceed the maximum nesting depth and enable validation.
class U(val s: String)
class A(val s: String)
class Q(val u: A)
class R(val u: Q)
class S(val u: R)
class T(val u: S)
class U(val u: T)
class V(val u: U)
class W(val v: V)
class X(val w: W)
Expand All @@ -1747,8 +1758,8 @@ internal class StructuredOutputsTest {
.isExactlyInstanceOf(IllegalArgumentException::class.java)
.hasMessage(
"Local validation failed for JSON schema derived from ${Z::class.java}:\n" +
" - #/properties/y/properties/x/properties/w/properties/v/properties/u" +
"/properties/s: Current nesting depth is 6, but maximum is 5."
" - #/properties/y/properties/x/properties/w/properties/v/properties/u/properties/u/properties/u/properties/u/properties/u/properties/u" +
"/properties/s: Current nesting depth is 11, but maximum is 10."
)
}

Expand All @@ -1757,20 +1768,24 @@ internal class StructuredOutputsTest {
fun responseFormatFromClassFailureWithValidationDefault() {
// Confirm that the default value of the `localValidation` argument is `YES` by expecting
// a validation error when that argument is not given an explicit value.
class U(val s: String)
class A(val s: String)
class Q(val u: A)
class R(val u: Q)
class S(val u: R)
class T(val u: S)
class U(val u: T)
class V(val u: U)
class W(val v: V)
class X(val w: W)
class Y(val x: X)
class Z(val y: Y)

// Use default for `localValidation` flag.
assertThatThrownBy { responseFormatFromClass(Z::class.java) }
.isExactlyInstanceOf(IllegalArgumentException::class.java)
.hasMessage(
"Local validation failed for JSON schema derived from ${Z::class.java}:\n" +
" - #/properties/y/properties/x/properties/w/properties/v/properties/u" +
"/properties/s: Current nesting depth is 6, but maximum is 5."
" - #/properties/y/properties/x/properties/w/properties/v/properties/u/properties/u/properties/u/properties/u/properties/u/properties/u" +
"/properties/s: Current nesting depth is 11, but maximum is 10."
)
}

Expand Down Expand Up @@ -1826,19 +1841,23 @@ internal class StructuredOutputsTest {
@Suppress("unused")
fun textConfigFromClassFailureWithValidation() {
// Exceed the maximum nesting depth and enable validation.
class U(val s: String)
class A(val s: String)
class Q(val u: A)
class R(val u: Q)
class S(val u: R)
class T(val u: S)
class U(val u: T)
class V(val u: U)
class W(val v: V)
class X(val w: W)
class Y(val x: X)
class Z(val y: Y)

assertThatThrownBy { textConfigFromClass(Z::class.java, JsonSchemaLocalValidation.YES) }
.isExactlyInstanceOf(IllegalArgumentException::class.java)
.hasMessage(
"Local validation failed for JSON schema derived from ${Z::class.java}:\n" +
" - #/properties/y/properties/x/properties/w/properties/v/properties/u" +
"/properties/s: Current nesting depth is 6, but maximum is 5."
" - #/properties/y/properties/x/properties/w/properties/v/properties/u/properties/u/properties/u/properties/u/properties/u/properties/u" +
"/properties/s: Current nesting depth is 11, but maximum is 10."
)
}

Expand All @@ -1847,7 +1866,12 @@ internal class StructuredOutputsTest {
fun textConfigFromClassFailureWithValidationDefault() {
// Confirm that the default value of the `localValidation` argument is `YES` by expecting
// a validation error when that argument is not given an explicit value.
class U(val s: String)
class A(val s: String)
class Q(val u: A)
class R(val u: Q)
class S(val u: R)
class T(val u: S)
class U(val u: T)
class V(val u: U)
class W(val v: V)
class X(val w: W)
Expand All @@ -1859,8 +1883,8 @@ internal class StructuredOutputsTest {
.isExactlyInstanceOf(IllegalArgumentException::class.java)
.hasMessage(
"Local validation failed for JSON schema derived from ${Z::class.java}:\n" +
" - #/properties/y/properties/x/properties/w/properties/v/properties/u" +
"/properties/s: Current nesting depth is 6, but maximum is 5."
" - #/properties/y/properties/x/properties/w/properties/v/properties/u/properties/u/properties/u/properties/u/properties/u/properties/u" +
"/properties/s: Current nesting depth is 11, but maximum is 10."
)
}

Expand Down Expand Up @@ -1954,7 +1978,12 @@ internal class StructuredOutputsTest {
@Suppress("unused")
fun functionToolFromClassFailureWithValidation() {
// Exceed the maximum nesting depth and enable validation.
class U(val s: String)
class A(val s: String)
class Q(val u: A)
class R(val u: Q)
class S(val u: R)
class T(val u: S)
class U(val u: T)
class V(val u: U)
class W(val v: V)
class X(val w: W)
Expand All @@ -1965,8 +1994,8 @@ internal class StructuredOutputsTest {
.isExactlyInstanceOf(IllegalArgumentException::class.java)
.hasMessage(
"Local validation failed for JSON schema derived from ${Z::class.java}:\n" +
" - #/properties/y/properties/x/properties/w/properties/v/properties/u" +
"/properties/s: Current nesting depth is 6, but maximum is 5."
" - #/properties/y/properties/x/properties/w/properties/v/properties/u/properties/u/properties/u/properties/u/properties/u/properties/u" +
"/properties/s: Current nesting depth is 11, but maximum is 10."
)
}

Expand All @@ -1975,7 +2004,12 @@ internal class StructuredOutputsTest {
fun functionToolFromClassFailureWithValidationDefault() {
// Confirm that the default value of the `localValidation` argument is `YES` by expecting a
// validation error when that argument is not given an explicit value.
class U(val s: String)
class A(val s: String)
class Q(val u: A)
class R(val u: Q)
class S(val u: R)
class T(val u: S)
class U(val u: T)
class V(val u: U)
class W(val v: V)
class X(val w: W)
Expand All @@ -1987,8 +2021,8 @@ internal class StructuredOutputsTest {
.isExactlyInstanceOf(IllegalArgumentException::class.java)
.hasMessage(
"Local validation failed for JSON schema derived from ${Z::class.java}:\n" +
" - #/properties/y/properties/x/properties/w/properties/v/properties/u" +
"/properties/s: Current nesting depth is 6, but maximum is 5."
" - #/properties/y/properties/x/properties/w/properties/v/properties/u/properties/u/properties/u/properties/u/properties/u/properties/u" +
"/properties/s: Current nesting depth is 11, but maximum is 10."
)
}

Expand Down Expand Up @@ -2048,7 +2082,12 @@ internal class StructuredOutputsTest {
@Suppress("unused")
fun responseFunctionToolFromClassFailureWithValidation() {
// Exceed the maximum nesting depth and enable validation.
class U(val s: String)
class A(val s: String)
class Q(val u: A)
class R(val u: Q)
class S(val u: R)
class T(val u: S)
class U(val u: T)
class V(val u: U)
class W(val v: V)
class X(val w: W)
Expand All @@ -2061,8 +2100,8 @@ internal class StructuredOutputsTest {
.isExactlyInstanceOf(IllegalArgumentException::class.java)
.hasMessage(
"Local validation failed for JSON schema derived from ${Z::class.java}:\n" +
" - #/properties/y/properties/x/properties/w/properties/v/properties/u" +
"/properties/s: Current nesting depth is 6, but maximum is 5."
" - #/properties/y/properties/x/properties/w/properties/v/properties/u/properties/u/properties/u/properties/u/properties/u/properties/u" +
"/properties/s: Current nesting depth is 11, but maximum is 10."
)
}

Expand All @@ -2071,7 +2110,12 @@ internal class StructuredOutputsTest {
fun responseFunctionToolFromClassFailureWithValidationDefault() {
// Confirm that the default value of the `localValidation` argument is `YES` by expecting
// a validation error when that argument is not given an explicit value.
class U(val s: String)
class A(val s: String)
class Q(val u: A)
class R(val u: Q)
class S(val u: R)
class T(val u: S)
class U(val u: T)
class V(val u: U)
class W(val v: V)
class X(val w: W)
Expand All @@ -2083,8 +2127,8 @@ internal class StructuredOutputsTest {
.isExactlyInstanceOf(IllegalArgumentException::class.java)
.hasMessage(
"Local validation failed for JSON schema derived from ${Z::class.java}:\n" +
" - #/properties/y/properties/x/properties/w/properties/v/properties/u" +
"/properties/s: Current nesting depth is 6, but maximum is 5."
" - #/properties/y/properties/x/properties/w/properties/v/properties/u/properties/u/properties/u/properties/u/properties/u/properties/u" +
"/properties/s: Current nesting depth is 11, but maximum is 10."
)
}

Expand Down
Loading