langserve
langserve copied to clipboard
Input type with `Optional` field breaks Playground
If a chain has an input type containing an optional field, the Playground page fails to load (blank page), and the following error is logged in the browser console:
index-400979f0.js:150 Uncaught Error: Unknown type: {"type":"null"}
at VC (index-400979f0.js:150:3067)
at Object.J6 [as uiSchema] (index-400979f0.js:150:3156)
at bh (index-400979f0.js:148:40890)
at index-400979f0.js:150:1495
at Array.map (<anonymous>)
at n0 (index-400979f0.js:150:1419)
at index-400979f0.js:255:25928
at z$ (index-400979f0.js:38:19538)
at Uw (index-400979f0.js:40:3139)
at p4 (index-400979f0.js:40:2351)
Example input type:
from pydantic import BaseModel
from typing import Optional
class Question(BaseModel):
question: str
datasource: Optional[str]
The generated input schema looks like:
{
"properties": {
"question": {
"title": "Question",
"type": "string"
},
"datasource": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Datasource"
}
},
"required": [
"question"
],
"title": "Question",
"type": "object"
}
and the {"type":"null"} seems to cause an issue with jsonforms.
Should the generated input schema be the following instead?
{
"properties": {
"question": {
"title": "Question",
"type": "string"
},
"datasource": {
"type": "string"
"title": "Datasource"
}
},
"required": [
"question"
],
"title": "Question",
"type": "object"
}
From reading through https://json-schema.org/understanding-json-schema/reference/object#required, it seems like the generated schema using anyOf and {"type":"null"} should be valid for optional properties, so perhaps this is a bug in jsonforms after all.
Any fix or workaround on this?
duplicate of: https://github.com/langchain-ai/langserve/issues/777