Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context failed to generate pydantic json schema, so chains containing Context steps not working in LangServe #27429

Open
5 tasks done
IlyaBokovenko opened this issue Oct 17, 2024 · 1 comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature Ɑ: core Related to langchain-core

Comments

@IlyaBokovenko
Copy link

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

from langchain_core.beta.runnables.context import Context, ContextSet, ContextGet

x = ContextSet('question')
x.config_schema().model_json_schema()

Error Message and Stack Trace (if applicable)


PydanticInvalidForJsonSchema Traceback (most recent call last)
Cell In[40], line 2
1 x = ContextSet('question')
----> 2 x.config_schema().model_json_schema()

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\main.py:476, in BaseModel.model_json_schema(cls, by_alias, ref_template, schema_generator, mode)
456 @classmethod
457 def model_json_schema(
458 cls,
(...)
462 mode: JsonSchemaMode = 'validation',
463 ) -> dict[str, Any]:
464 """Generates a JSON schema for a model class.
465
466 Args:
(...)
474 The JSON schema for the given model class.
475 """
--> 476 return model_json_schema(
477 cls, by_alias=by_alias, ref_template=ref_template, schema_generator=schema_generator, mode=mode
478 )

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:2280, in model_json_schema(cls, by_alias, ref_template, schema_generator, mode)
2277 raise AttributeError('model_json_schema() must be called on a subclass of BaseModel, not BaseModel itself.')
2279 assert not isinstance(cls.pydantic_core_schema, _mock_val_ser.MockCoreSchema), 'this is a bug! please report it'
-> 2280 return schema_generator_instance.generate(cls.pydantic_core_schema, mode=mode)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:415, in GenerateJsonSchema.generate(self, schema, mode)
408 if self._used:
409 raise PydanticUserError(
410 'This JSON schema generator has already been used to generate a JSON schema. '
411 f'You must create a new instance of {type(self).name} to generate a new JSON schema.',
412 code='json-schema-already-used',
413 )
--> 415 json_schema: JsonSchemaValue = self.generate_inner(schema)
416 json_ref_counts = self.get_json_ref_counts(json_schema)
418 ref = cast(JsonRef, json_schema.get('$ref'))

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:552, in GenerateJsonSchema.generate_inner(self, schema)
548 return json_schema
550 current_handler = _schema_generation_shared.GenerateJsonSchemaHandler(self, new_handler_func)
--> 552 json_schema = current_handler(schema)
553 if _core_utils.is_core_schema(schema):
554 json_schema = populate_defs(schema, json_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic_internal_schema_generation_shared.py:37, in GenerateJsonSchemaHandler.call(self, core_schema)
36 def call(self, core_schema: CoreSchemaOrField, /) -> JsonSchemaValue:
---> 37 return self.handler(core_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:527, in GenerateJsonSchema.generate_inner..new_handler_func(schema_or_field, current_handler, js_modify_function)
522 def new_handler_func(
523 schema_or_field: CoreSchemaOrField,
524 current_handler: GetJsonSchemaHandler = current_handler,
525 js_modify_function: GetJsonSchemaFunction = js_modify_function,
526 ) -> JsonSchemaValue:
--> 527 json_schema = js_modify_function(schema_or_field, current_handler)
528 if _core_utils.is_core_schema(schema_or_field):
529 json_schema = populate_defs(schema_or_field, json_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\main.py:697, in BaseModel.get_pydantic_json_schema(cls, core_schema, handler)
673 @classmethod
674 def get_pydantic_json_schema(
675 cls,
(...)
678 /,
679 ) -> JsonSchemaValue:
680 """Hook into generating the model's JSON schema.
681
682 Args:
(...)
695 A JSON schema, as a Python object.
696 """
--> 697 return handler(core_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic_internal_schema_generation_shared.py:37, in GenerateJsonSchemaHandler.call(self, core_schema)
36 def call(self, core_schema: CoreSchemaOrField, /) -> JsonSchemaValue:
---> 37 return self.handler(core_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:527, in GenerateJsonSchema.generate_inner..new_handler_func(schema_or_field, current_handler, js_modify_function)
522 def new_handler_func(
523 schema_or_field: CoreSchemaOrField,
524 current_handler: GetJsonSchemaHandler = current_handler,
525 js_modify_function: GetJsonSchemaFunction = js_modify_function,
526 ) -> JsonSchemaValue:
--> 527 json_schema = js_modify_function(schema_or_field, current_handler)
528 if _core_utils.is_core_schema(schema_or_field):
529 json_schema = populate_defs(schema_or_field, json_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic_internal_generate_schema.py:272, in modify_model_json_schema(schema_or_field, handler, cls, title)
268 from ._dataclasses import is_builtin_dataclass
270 BaseModel = import_cached_base_model()
--> 272 json_schema = handler(schema_or_field)
273 original_schema = handler.resolve_ref_schema(json_schema)
274 if title is not None:

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic_internal_schema_generation_shared.py:37, in GenerateJsonSchemaHandler.call(self, core_schema)
36 def call(self, core_schema: CoreSchemaOrField, /) -> JsonSchemaValue:
---> 37 return self.handler(core_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:511, in GenerateJsonSchema.generate_inner..handler_func(schema_or_field)
509 if _core_utils.is_core_schema(schema_or_field) or _core_utils.is_core_schema_field(schema_or_field):
510 generate_for_schema_type = self._schema_type_to_method[schema_or_field['type']]
--> 511 json_schema = generate_for_schema_type(schema_or_field)
512 else:
513 raise TypeError(f'Unexpected schema type: schema={schema_or_field}')

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:1415, in GenerateJsonSchema.model_schema(self, schema)
1412 title = config.get('title')
1414 with self._config_wrapper_stack.push(config):
-> 1415 json_schema = self.generate_inner(schema['schema'])
1417 json_schema_extra = config.get('json_schema_extra')
1418 if cls.pydantic_root_model:

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:552, in GenerateJsonSchema.generate_inner(self, schema)
548 return json_schema
550 current_handler = _schema_generation_shared.GenerateJsonSchemaHandler(self, new_handler_func)
--> 552 json_schema = current_handler(schema)
553 if _core_utils.is_core_schema(schema):
554 json_schema = populate_defs(schema, json_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic_internal_schema_generation_shared.py:37, in GenerateJsonSchemaHandler.call(self, core_schema)
36 def call(self, core_schema: CoreSchemaOrField, /) -> JsonSchemaValue:
---> 37 return self.handler(core_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:511, in GenerateJsonSchema.generate_inner..handler_func(schema_or_field)
509 if _core_utils.is_core_schema(schema_or_field) or _core_utils.is_core_schema_field(schema_or_field):
510 generate_for_schema_type = self._schema_type_to_method[schema_or_field['type']]
--> 511 json_schema = generate_for_schema_type(schema_or_field)
512 else:
513 raise TypeError(f'Unexpected schema type: schema={schema_or_field}')

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:1510, in GenerateJsonSchema.model_fields_schema(self, schema)
1508 if self.mode == 'serialization':
1509 named_required_fields.extend(self._name_required_computed_fields(schema.get('computed_fields', [])))
-> 1510 json_schema = self._named_required_fields_schema(named_required_fields)
1511 extras_schema = schema.get('extras_schema', None)
1512 if extras_schema is not None:

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:1318, in GenerateJsonSchema._named_required_fields_schema(self, named_required_fields)
1316 name = self._get_alias_name(field, name)
1317 try:
-> 1318 field_json_schema = self.generate_inner(field).copy()
1319 except PydanticOmit:
1320 continue

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:552, in GenerateJsonSchema.generate_inner(self, schema)
548 return json_schema
550 current_handler = _schema_generation_shared.GenerateJsonSchemaHandler(self, new_handler_func)
--> 552 json_schema = current_handler(schema)
553 if _core_utils.is_core_schema(schema):
554 json_schema = populate_defs(schema, json_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic_internal_schema_generation_shared.py:37, in GenerateJsonSchemaHandler.call(self, core_schema)
36 def call(self, core_schema: CoreSchemaOrField, /) -> JsonSchemaValue:
---> 37 return self.handler(core_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:545, in GenerateJsonSchema.generate_inner..new_handler_func(schema_or_field, current_handler, js_modify_function)
540 def new_handler_func(
541 schema_or_field: CoreSchemaOrField,
542 current_handler: GetJsonSchemaHandler = current_handler,
543 js_modify_function: GetJsonSchemaFunction = js_modify_function,
544 ) -> JsonSchemaValue:
--> 545 json_schema = js_modify_function(schema_or_field, current_handler)
546 if _core_utils.is_core_schema(schema_or_field):
547 json_schema = populate_defs(schema_or_field, json_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic_internal_generate_schema.py:2469, in get_json_schema_update_func..json_schema_update_func(core_schema_or_field, handler)
2466 def json_schema_update_func(
2467 core_schema_or_field: CoreSchemaOrField, handler: GetJsonSchemaHandler
2468 ) -> JsonSchemaValue:
-> 2469 json_schema = {**handler(core_schema_or_field), **json_schema_update}
2470 add_json_schema_extra(json_schema, json_schema_extra)
2471 return json_schema

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic_internal_schema_generation_shared.py:37, in GenerateJsonSchemaHandler.call(self, core_schema)
36 def call(self, core_schema: CoreSchemaOrField, /) -> JsonSchemaValue:
---> 37 return self.handler(core_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:511, in GenerateJsonSchema.generate_inner..handler_func(schema_or_field)
509 if _core_utils.is_core_schema(schema_or_field) or _core_utils.is_core_schema_field(schema_or_field):
510 generate_for_schema_type = self._schema_type_to_method[schema_or_field['type']]
--> 511 json_schema = generate_for_schema_type(schema_or_field)
512 else:
513 raise TypeError(f'Unexpected schema type: schema={schema_or_field}')

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:1386, in GenerateJsonSchema.model_field_schema(self, schema)
1377 def model_field_schema(self, schema: core_schema.ModelField) -> JsonSchemaValue:
1378 """Generates a JSON schema that matches a schema that defines a model field.
1379
1380 Args:
(...)
1384 The generated JSON schema.
1385 """
-> 1386 return self.generate_inner(schema['schema'])

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:552, in GenerateJsonSchema.generate_inner(self, schema)
548 return json_schema
550 current_handler = _schema_generation_shared.GenerateJsonSchemaHandler(self, new_handler_func)
--> 552 json_schema = current_handler(schema)
553 if _core_utils.is_core_schema(schema):
554 json_schema = populate_defs(schema, json_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic_internal_schema_generation_shared.py:37, in GenerateJsonSchemaHandler.call(self, core_schema)
36 def call(self, core_schema: CoreSchemaOrField, /) -> JsonSchemaValue:
---> 37 return self.handler(core_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:511, in GenerateJsonSchema.generate_inner..handler_func(schema_or_field)
509 if _core_utils.is_core_schema(schema_or_field) or _core_utils.is_core_schema_field(schema_or_field):
510 generate_for_schema_type = self._schema_type_to_method[schema_or_field['type']]
--> 511 json_schema = generate_for_schema_type(schema_or_field)
512 else:
513 raise TypeError(f'Unexpected schema type: schema={schema_or_field}')

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:1042, in GenerateJsonSchema.default_schema(self, schema)
1033 def default_schema(self, schema: core_schema.WithDefaultSchema) -> JsonSchemaValue:
1034 """Generates a JSON schema that matches a schema with a default value.
1035
1036 Args:
(...)
1040 The generated JSON schema.
1041 """
-> 1042 json_schema = self.generate_inner(schema['schema'])
1044 if 'default' not in schema:
1045 return json_schema

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:552, in GenerateJsonSchema.generate_inner(self, schema)
548 return json_schema
550 current_handler = _schema_generation_shared.GenerateJsonSchemaHandler(self, new_handler_func)
--> 552 json_schema = current_handler(schema)
553 if _core_utils.is_core_schema(schema):
554 json_schema = populate_defs(schema, json_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic_internal_schema_generation_shared.py:37, in GenerateJsonSchemaHandler.call(self, core_schema)
36 def call(self, core_schema: CoreSchemaOrField, /) -> JsonSchemaValue:
---> 37 return self.handler(core_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:527, in GenerateJsonSchema.generate_inner..new_handler_func(schema_or_field, current_handler, js_modify_function)
522 def new_handler_func(
523 schema_or_field: CoreSchemaOrField,
524 current_handler: GetJsonSchemaHandler = current_handler,
525 js_modify_function: GetJsonSchemaFunction = js_modify_function,
526 ) -> JsonSchemaValue:
--> 527 json_schema = js_modify_function(schema_or_field, current_handler)
528 if _core_utils.is_core_schema(schema_or_field):
529 json_schema = populate_defs(schema_or_field, json_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\main.py:697, in BaseModel.get_pydantic_json_schema(cls, core_schema, handler)
673 @classmethod
674 def get_pydantic_json_schema(
675 cls,
(...)
678 /,
679 ) -> JsonSchemaValue:
680 """Hook into generating the model's JSON schema.
681
682 Args:
(...)
695 A JSON schema, as a Python object.
696 """
--> 697 return handler(core_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic_internal_schema_generation_shared.py:37, in GenerateJsonSchemaHandler.call(self, core_schema)
36 def call(self, core_schema: CoreSchemaOrField, /) -> JsonSchemaValue:
---> 37 return self.handler(core_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:527, in GenerateJsonSchema.generate_inner..new_handler_func(schema_or_field, current_handler, js_modify_function)
522 def new_handler_func(
523 schema_or_field: CoreSchemaOrField,
524 current_handler: GetJsonSchemaHandler = current_handler,
525 js_modify_function: GetJsonSchemaFunction = js_modify_function,
526 ) -> JsonSchemaValue:
--> 527 json_schema = js_modify_function(schema_or_field, current_handler)
528 if _core_utils.is_core_schema(schema_or_field):
529 json_schema = populate_defs(schema_or_field, json_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic_internal_generate_schema.py:272, in modify_model_json_schema(schema_or_field, handler, cls, title)
268 from ._dataclasses import is_builtin_dataclass
270 BaseModel = import_cached_base_model()
--> 272 json_schema = handler(schema_or_field)
273 original_schema = handler.resolve_ref_schema(json_schema)
274 if title is not None:

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic_internal_schema_generation_shared.py:37, in GenerateJsonSchemaHandler.call(self, core_schema)
36 def call(self, core_schema: CoreSchemaOrField, /) -> JsonSchemaValue:
---> 37 return self.handler(core_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:511, in GenerateJsonSchema.generate_inner..handler_func(schema_or_field)
509 if _core_utils.is_core_schema(schema_or_field) or _core_utils.is_core_schema_field(schema_or_field):
510 generate_for_schema_type = self._schema_type_to_method[schema_or_field['type']]
--> 511 json_schema = generate_for_schema_type(schema_or_field)
512 else:
513 raise TypeError(f'Unexpected schema type: schema={schema_or_field}')

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:1415, in GenerateJsonSchema.model_schema(self, schema)
1412 title = config.get('title')
1414 with self._config_wrapper_stack.push(config):
-> 1415 json_schema = self.generate_inner(schema['schema'])
1417 json_schema_extra = config.get('json_schema_extra')
1418 if cls.pydantic_root_model:

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:552, in GenerateJsonSchema.generate_inner(self, schema)
548 return json_schema
550 current_handler = _schema_generation_shared.GenerateJsonSchemaHandler(self, new_handler_func)
--> 552 json_schema = current_handler(schema)
553 if _core_utils.is_core_schema(schema):
554 json_schema = populate_defs(schema, json_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic_internal_schema_generation_shared.py:37, in GenerateJsonSchemaHandler.call(self, core_schema)
36 def call(self, core_schema: CoreSchemaOrField, /) -> JsonSchemaValue:
---> 37 return self.handler(core_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:511, in GenerateJsonSchema.generate_inner..handler_func(schema_or_field)
509 if _core_utils.is_core_schema(schema_or_field) or _core_utils.is_core_schema_field(schema_or_field):
510 generate_for_schema_type = self._schema_type_to_method[schema_or_field['type']]
--> 511 json_schema = generate_for_schema_type(schema_or_field)
512 else:
513 raise TypeError(f'Unexpected schema type: schema={schema_or_field}')

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:1510, in GenerateJsonSchema.model_fields_schema(self, schema)
1508 if self.mode == 'serialization':
1509 named_required_fields.extend(self._name_required_computed_fields(schema.get('computed_fields', [])))
-> 1510 json_schema = self._named_required_fields_schema(named_required_fields)
1511 extras_schema = schema.get('extras_schema', None)
1512 if extras_schema is not None:

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:1318, in GenerateJsonSchema._named_required_fields_schema(self, named_required_fields)
1316 name = self._get_alias_name(field, name)
1317 try:
-> 1318 field_json_schema = self.generate_inner(field).copy()
1319 except PydanticOmit:
1320 continue

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:552, in GenerateJsonSchema.generate_inner(self, schema)
548 return json_schema
550 current_handler = _schema_generation_shared.GenerateJsonSchemaHandler(self, new_handler_func)
--> 552 json_schema = current_handler(schema)
553 if _core_utils.is_core_schema(schema):
554 json_schema = populate_defs(schema, json_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic_internal_schema_generation_shared.py:37, in GenerateJsonSchemaHandler.call(self, core_schema)
36 def call(self, core_schema: CoreSchemaOrField, /) -> JsonSchemaValue:
---> 37 return self.handler(core_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:545, in GenerateJsonSchema.generate_inner..new_handler_func(schema_or_field, current_handler, js_modify_function)
540 def new_handler_func(
541 schema_or_field: CoreSchemaOrField,
542 current_handler: GetJsonSchemaHandler = current_handler,
543 js_modify_function: GetJsonSchemaFunction = js_modify_function,
544 ) -> JsonSchemaValue:
--> 545 json_schema = js_modify_function(schema_or_field, current_handler)
546 if _core_utils.is_core_schema(schema_or_field):
547 json_schema = populate_defs(schema_or_field, json_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic_internal_generate_schema.py:2469, in get_json_schema_update_func..json_schema_update_func(core_schema_or_field, handler)
2466 def json_schema_update_func(
2467 core_schema_or_field: CoreSchemaOrField, handler: GetJsonSchemaHandler
2468 ) -> JsonSchemaValue:
-> 2469 json_schema = {**handler(core_schema_or_field), **json_schema_update}
2470 add_json_schema_extra(json_schema, json_schema_extra)
2471 return json_schema

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic_internal_schema_generation_shared.py:37, in GenerateJsonSchemaHandler.call(self, core_schema)
36 def call(self, core_schema: CoreSchemaOrField, /) -> JsonSchemaValue:
---> 37 return self.handler(core_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:511, in GenerateJsonSchema.generate_inner..handler_func(schema_or_field)
509 if _core_utils.is_core_schema(schema_or_field) or _core_utils.is_core_schema_field(schema_or_field):
510 generate_for_schema_type = self._schema_type_to_method[schema_or_field['type']]
--> 511 json_schema = generate_for_schema_type(schema_or_field)
512 else:
513 raise TypeError(f'Unexpected schema type: schema={schema_or_field}')

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:1386, in GenerateJsonSchema.model_field_schema(self, schema)
1377 def model_field_schema(self, schema: core_schema.ModelField) -> JsonSchemaValue:
1378 """Generates a JSON schema that matches a schema that defines a model field.
1379
1380 Args:
(...)
1384 The generated JSON schema.
1385 """
-> 1386 return self.generate_inner(schema['schema'])

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:552, in GenerateJsonSchema.generate_inner(self, schema)
548 return json_schema
550 current_handler = _schema_generation_shared.GenerateJsonSchemaHandler(self, new_handler_func)
--> 552 json_schema = current_handler(schema)
553 if _core_utils.is_core_schema(schema):
554 json_schema = populate_defs(schema, json_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic_internal_schema_generation_shared.py:37, in GenerateJsonSchemaHandler.call(self, core_schema)
36 def call(self, core_schema: CoreSchemaOrField, /) -> JsonSchemaValue:
---> 37 return self.handler(core_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:511, in GenerateJsonSchema.generate_inner..handler_func(schema_or_field)
509 if _core_utils.is_core_schema(schema_or_field) or _core_utils.is_core_schema_field(schema_or_field):
510 generate_for_schema_type = self._schema_type_to_method[schema_or_field['type']]
--> 511 json_schema = generate_for_schema_type(schema_or_field)
512 else:
513 raise TypeError(f'Unexpected schema type: schema={schema_or_field}')

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:1042, in GenerateJsonSchema.default_schema(self, schema)
1033 def default_schema(self, schema: core_schema.WithDefaultSchema) -> JsonSchemaValue:
1034 """Generates a JSON schema that matches a schema with a default value.
1035
1036 Args:
(...)
1040 The generated JSON schema.
1041 """
-> 1042 json_schema = self.generate_inner(schema['schema'])
1044 if 'default' not in schema:
1045 return json_schema

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:552, in GenerateJsonSchema.generate_inner(self, schema)
548 return json_schema
550 current_handler = _schema_generation_shared.GenerateJsonSchemaHandler(self, new_handler_func)
--> 552 json_schema = current_handler(schema)
553 if _core_utils.is_core_schema(schema):
554 json_schema = populate_defs(schema, json_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic_internal_schema_generation_shared.py:37, in GenerateJsonSchemaHandler.call(self, core_schema)
36 def call(self, core_schema: CoreSchemaOrField, /) -> JsonSchemaValue:
---> 37 return self.handler(core_schema)

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:511, in GenerateJsonSchema.generate_inner..handler_func(schema_or_field)
509 if _core_utils.is_core_schema(schema_or_field) or _core_utils.is_core_schema_field(schema_or_field):
510 generate_for_schema_type = self._schema_type_to_method[schema_or_field['type']]
--> 511 json_schema = generate_for_schema_type(schema_or_field)
512 else:
513 raise TypeError(f'Unexpected schema type: schema={schema_or_field}')

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:835, in GenerateJsonSchema.callable_schema(self, schema)
824 def callable_schema(self, schema: core_schema.CallableSchema) -> JsonSchemaValue:
825 """Generates a JSON schema that matches a callable value.
826
827 Unless overridden in a subclass, this raises an error.
(...)
833 The generated JSON schema.
834 """
--> 835 return self.handle_invalid_for_json_schema(schema, 'core_schema.CallableSchema')

File C:\Projects\AI\ll-rag.venv\lib\site-packages\pydantic\json_schema.py:2185, in GenerateJsonSchema.handle_invalid_for_json_schema(self, schema, error_info)
2184 def handle_invalid_for_json_schema(self, schema: CoreSchemaOrField, error_info: str) -> JsonSchemaValue:
-> 2185 raise PydanticInvalidForJsonSchema(f'Cannot generate a JsonSchema for {error_info}')

PydanticInvalidForJsonSchema: Cannot generate a JsonSchema for core_schema.CallableSchema

For further information visit https://errors.pydantic.dev/2.9/u/invalid-for-json-schema

Description

The code produces error PydanticInvalidForJsonSchema: Cannot generate a JsonSchema for core_schema.CallableSchema`
So when I try to use Context in my chain the LangServe - it raises error when I try to go to playground

System Info

System Information

OS: Windows
OS Version: 10.0.19045
Python Version: 3.10.0 (tags/v3.10.0:b494f59, Oct 4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)]

Package Information

langchain_core: 0.3.8
langchain: 0.3.1
langchain_community: 0.3.1
langsmith: 0.1.130
langchain_chroma: 0.1.4
langchain_experimental: 0.3.2
langchain_openai: 0.2.1
langchain_text_splitters: 0.3.0
langchainhub: 0.1.21
langserve: 0.3.0

Optional packages not installed

langgraph

Other Dependencies

aiohttp: 3.10.8
async-timeout: 4.0.3
chromadb: 0.5.11
dataclasses-json: 0.6.7
fastapi: 0.115.0
httpx: 0.27.2
jsonpatch: 1.33
numpy: 1.26.4
openai: 1.46.1
orjson: 3.10.7
packaging: 24.1
pydantic: 2.9.2
pydantic-settings: 2.5.2
PyYAML: 6.0.2
requests: 2.32.3
requests-toolbelt: 1.0.0
SQLAlchemy: 2.0.35
sse-starlette: 1.8.2
tenacity: 8.5.0
tiktoken: 0.7.0
types-requests: 2.32.0.20240914
typing-extensions: 4.12.2

@dosubot dosubot bot added Ɑ: core Related to langchain-core 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature labels Oct 17, 2024
@eyurtsev
Copy link
Collaborator

Use with_types to specify the schema manually as a work-around. schema inference fails for more complex LCEL chains, and at the moment we're not prioritizing fixing all of the edge cases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature Ɑ: core Related to langchain-core
Projects
None yet
Development

No branches or pull requests

2 participants