Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[BUG]: ensure_type_in_schemas incorrectly forces empty schemas {} to {"type": "object"} in anyOf/oneOf

Aperta Adatta ai principianti
#8,073 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@sallyw02 ci sta già lavorando.

Dal 12/10/2026.

  • #8106 di @sallyw02 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
ai, backend

Direzione di ricerca

Inizia da lib/crewai/src/crewai/utilities/pydantic_schema_utils.py e analizza ensure_type_in_schemas() in relazione alla gestione degli schemi vuoti descritta nell’issue. Verifica come la funzione gestisce anyOf e oneOf, quindi controlla i test esistenti per questi schemi. Il risultato atteso è che {} mantenga il suo significato di JSON Schema senza vincoli e che venga preservato il comportamento previsto della modalità strict.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description

In lib/crewai/src/crewai/utilities/pydantic_schema_utils.py, ensure_type_in_schemas() converts empty schemas {} inside anyOf / oneOf into {"type": "object"}:

# lib/crewai/src/crewai/utilities/pydantic_schema_utils.py (lines 290-292)
for i, schema in enumerate(schema_list):
    if isinstance(schema, dict) and schema == {}:
        schema_list[i] = {"type": "object"}

In JSON Schema specification, {} represents an unconstrained schema (accepting any value, including primitives such as strings, numbers, and booleans). Converting {} to {"type": "object"} corrupts schema semantics:

  1. When a tool has a parameter typed as Any or Optional[Any], Pydantic generates {"anyOf": [{}, {"type": "null"}]}.
  2. ensure_type_in_schemas transforms this into {"anyOf": [{"type": "object"}, {"type": "null"}]}.
  3. As a result, the tool parameter is restricted to dictionaries/objects only. If an LLM returns a valid scalar (e.g. 42 or "ok"), validation fails or the LLM is forced to return {} instead of the requested scalar.
Steps to Reproduce
from copy import deepcopy
from crewai.utilities.pydantic_schema_utils import ensure_type_in_schemas

schema = {"anyOf": [{}, {"type": "null"}]}
result = ensure_type_in_schemas(deepcopy(schema))
print(result)

# Observed:
# {'anyOf': [{'type': 'object'}, {'type': 'null'}]}
Expected Behavior

Empty schemas {} (representing Any) should not be unconditionally converted to {"type": "object"}. If OpenAI strict mode requires an explicit type, converting {} to an object restricts valid scalar arguments. The conversion should either preserve {} when not enforcing strict object constraints or avoid coercing unconstrained types to object.

Additional Context
  • Python environment: Python 3.10+ / Pydantic v2
  • File: lib/crewai/src/crewai/utilities/pydantic_schema_utils.py
Lingua principale
Python
Stelle
60.1k
Fork
8.9k
Merge medio
1g 7h
PR unite (30g)
184

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di crewAIInc/crewAI

Tutte le issue di crewAIInc/crewAI

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.